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