GATE Computer ScienceHardGATE CS (PYQ pattern)
In the BST obtained by inserting 40, 20, 60, 10, 30, 50, 5, 15, 3, 1, 25, 55, 57, 56 in order, how many nodes have a balance factor (height of left subtree minus height of right subtree, empty = -1) whose absolute value exceeds 1?
- A. 7
- B. 5
- C. 6
- D. 4
Correct answer: C. 6
Compute each node's subtree heights; the nodes with |bf| >= 2 are counted: 6 (the tree is not AVL).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A binary tree is stored in level order with null children written as : 1 2 3 4 5 6 7 8 (a null child still consumes a slot only if its…
- Non-negative numbers are stored as singly linked lists of digits with the least significant digit first. A = 9 -> 9 -> 8 -> 5 (the number…
- A priority queue is a sorted singly linked list (ascending). Insert scans from the head, comparing the new key with each node, and stops…
- Keys 1..7 form a max-heap stored in a 0-indexed array (children of i are 2i+1, 2i+2). The key 5 is the third largest. In how many…
- A hash table starts with 7 slots, uses linear probing with h(k) = k mod size, and after each insertion, if the load factor exceeds 0.7, it…
- A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T…