GATE Computer ScienceVery hardGATE CS (PYQ pattern)
In the BST built by inserting 40, 20, 60, 10, 30, 50, 70, 25, 35, 45, 55, 65, 75, 22 in order, what are the inorder successor of 35, the inorder predecessor of 40 and the inorder successor of 22, written in that order?
- A. 40, 35, 25
- B. 40, 35, 30
- C. 45, 35, 25
- D. 40, 30, 25
Correct answer: A. 40, 35, 25
35 is the largest key in the left subtree of 30, so its successor is the nearest ancestor of which it is in the left subtree: 40. The predecessor of 40 is the rightmost node of its left subtree: 35. 22 has no right child; its successor is its nearest ancestor reached from the left: 25.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int f(int n) { if (n == 0) return 1; return f(n - 1) + f(n - 1); } How many calls to f (including the first) does f(10) make?
- Keys 30, 10, 20, 50, 40, 60, 45 are inserted into an initially empty AVL tree in this order. What are the root and the total number of…
- 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…
- 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?