Sequence the following steps of the algorithm for checking whether a string is a palindrome or not, using "deque":
(A) Insert the character in deque as a normal queue using INSERTREAR.
(B) Traverse these strings from left to right, one character at a time. Repeat this step and the above one for all characters in these strings.
(C) If these characters match, repeat these steps until the deque is empty or contains one character. Otherwise, stop, as string is not a palindrome.
(D) Remove one character from the front and one character from the rear end of the deque. Match these two removed characters.
Sequence the following steps of the algorithm for checking whether a string is a palindrome or not, using "deque":
(A) Insert the character in deque as a normal queue using INSERTREAR.
(B) Traverse these strings from left to right, one character at a time. Repeat this step and the above one for all characters in these strings.
(C) If these characters match, repeat these steps until the deque is empty or contains one character. Otherwise, stop, as string is not a palindrome.
(D) Remove one character from the front and one character from the rear end of the deque. Match these two removed characters.
Solution
(B) Traverse the string from left to right, one character at a time.
(A) Insert each character at the rear of the deque using INSERTREAR. Step (B) says to repeat "this step and the above one", so (A) comes right after (B) and the pair repeats for every character.
(D) Once all characters are inserted, remove one character from the front and one from the rear, and compare them.
(C) If they match, repeat until the deque is empty or has one character left. Otherwise stop, because the string is not a palindrome.
Option 2: (B) refers to "the above one" for repetition, so (A) must come before (B), not after it.
Options 1 and 3: removing and matching (D) cannot happen before every character has been inserted, and (C) depends on the result of (D), so it cannot come first.
Related questions:
2025: 14 May Shift 1
2025: 21 May Shift 1