GATE Computer ScienceModerateGATE CS (PYQ pattern)
Which one of the following is NOT a possible pop sequence when 1, 2, 3, 4, 5 are pushed in order (pops interleaved arbitrarily)? P: 2 1 4 3 5 Q: 3 4 2 1 5 R: 4 3 5 1 2 S: 1 5 4 3 2
- A. R
- B. P
- C. Q
- D. S
Correct answer: A. R
For R, after popping 4 and 3 the stack holds 1, 2 (2 on top), so 2 must come out before 1; R pops 1 before 2. P, Q and S are all producible.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 125 keys are hashed uniformly and independently into 50 chains of a hash table. What are the expected number of keys examined in an…
- The preorder and inorder traversals of a binary tree are 7 3 1 2 5 4 6 and 1 3 2 7 4 5 6 respectively. What is its postorder traversal?
- int a[] = {2, 4, 6, 8, 10}; int p = a + 1, q = a + 4; printf("%d %d %d", p + q, (q - 2), q - p); What is printed?
- int f(void) { static int c = 0; return ++c; } int main() { int x = f() || f(); int y = f() && f() > 3 ? f() : -f(); printf("%d %d %d", x…
- In a min-heap stored 1-indexed in an array with children of i at 2i and 2i+1, a node at index 77 is replaced by a smaller key and sifted…
- int a[] = {5, 3, 8, 4, 2, 9, 1, 7, 6, 10}; int st[10], top = -1, nge[10]; for (int i = 0; i < 10; i++) nge[i] = -1; for (int i = 0; i <…