GATE Computer ScienceEasyGATE CS (PYQ pattern)
A routine reverses the entire string in place and then reverses each maximal run of non-space characters in place. It is applied twice in a row to "stack and queue". What is the string after the second application, and what is it after just the first?
- A. "queue and stack" and "stack and queue"
- B. "stack and queue" and "queue and stack"
- C. "eucuq dna kcats" and "queue and stack"
- D. "stack and queue" and "eucuq dna kcats"
Correct answer: B. "stack and queue" and "queue and stack"
One application reverses the order of the words (queue and stack); the second restores the original order. After one: "queue and stack"; after two: "stack and queue".
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A singly linked list 1 -> 2 -> ... -> 20 undergoes two passes: first every 3rd node (by current position) is deleted, then in the…
- int x = 1; int inc(void) { return x += 1; } int dbl(void) { return x = 2; } int sq(void) { return x = x; } int (fp[3])(void) = {inc, dbl…
- A table of size 13 uses double hashing, probe i of key k is (k mod 13 + i (1 + k mod 11)) mod 13. Keys 18, 41, 22, 44, 59, 32, 31, 73 are…
- A BST on 31 keys is perfectly balanced (all 5 levels full). Searching for each of the 31 keys with equal probability, what is the average…
- Keys 1 to 5 are inserted into an empty BST in a uniformly random order of the 120 possible orders. In how many of the orders does key 3…
- Iterative postorder uses two stacks: push the root on S1; repeat: pop x from S1, push x on S2, push x's left child then its right child on…