check 1 procedure check1 (a1,... An : string) answer := true for i := 1 to [n/2] if ai + a+1-i then answer := false return answer check 2 procedure check2 (a1,... An : string) answer := true for i := 1 to n if ai + an+1-i then answer := false return answer

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please select all correct answers from the following choices. 

(A) Procedure check 1 is correct

(B) Procedure check 2 is incorrect

(C) Both procedures are finite

(D) Correct or not, procedure check 2 takes longer to complete than procedure check 1

(E) Procedure check 2 is general, but procedure check 1 is not

 

Consider the following two procedures. Each procedure is intended to
check whether a string is a palindrome (that is, reads the same forward
and backward, like pop or nursesrun).
Each procedure takes a string as input and should output if the input
string is a palindrome and false otherwise.
In the pseudocode that follows, a1, a2, etc., refer to the individual
characters of the string. For example, in the string wow, ai =
W, a2 = 0, and
A3 = w.
Transcribed Image Text:Consider the following two procedures. Each procedure is intended to check whether a string is a palindrome (that is, reads the same forward and backward, like pop or nursesrun). Each procedure takes a string as input and should output if the input string is a palindrome and false otherwise. In the pseudocode that follows, a1, a2, etc., refer to the individual characters of the string. For example, in the string wow, ai = W, a2 = 0, and A3 = w.
check 1
procedure check1 (a1,... an : string)
answer
:= true
for i:= 1 to [n/2]
if a; # an+1-i then answer
:= false
return answer
check 2
procedure check2 (a1,... An : string)
answer
:= true
for i := 1 to n
if ai + an+1-i then answer
:= false
return answer
Transcribed Image Text:check 1 procedure check1 (a1,... an : string) answer := true for i:= 1 to [n/2] if a; # an+1-i then answer := false return answer check 2 procedure check2 (a1,... An : string) answer := true for i := 1 to n if ai + an+1-i then answer := false return answer
Expert Solution
Step 1: explanation

Both the procedures check if the string is palindrome or not.

Answer they return the answer correctly.

But the procedure (check 1) is more efficient in the terms of run time as compared to procedure 2(check 2).

In check 1 we will only traverse half of the string and tell if string is palindrome or not while in check 2 we will have to traverse the whole string and in doing so we will double check each string if they are equal of not.

Both produce the same output but the check1 is more efficient.

Hope it helps.

 

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Asymptotic Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education