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
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

![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F99573f31-291c-4e04-b309-59771314403d%2Fdfaa6b95-9419-4312-888f-9b19f9851217%2Fbjdvbhj_processed.png&w=3840&q=75)

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.
Step by step
Solved in 2 steps









