Data Structures & AlgorithmsHardGATE CS · Product-company placement
Keys 92, 49, 31, 85, 28, 73, 29, 81, 90 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- A. 49, 28, 31, 29, 85, 73, 81, 92, 90
- B. 92, 49, 31, 28, 29, 85, 73, 81, 90
- C. 28, 31, 29, 81, 73, 90, 92, 85, 49
- D. 49, 29, 28, 31, 85, 73, 81, 92, 90
Correct answer: D. 49, 29, 28, 31, 85, 73, 81, 92, 90
Rebalance at the lowest unbalanced ancestor after each insert; the rotations performed are LL at 92, LL at 92, LR at 31. Treating an LR/RL case as a single rotation leaves a wrong (still unbalanced) shape.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- The words graph, green, greed, grape, grass are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a…
- In the DAG with edges B→E, C→A, C→G, D→A, D→B, D→C, D→F, D→G, F→A, F→B, F→C, how many distinct directed paths are there from D to G, and…
- A DAG on vertices A–G has edges B→A, B→D, B→F, E→C, F→A, F→E, G→A, G→C. What order does Kahn's algorithm that always removes the…
- A 3-ary max-heap is stored in a 0-indexed array (children of i at 3i + 1 … 3i + 3): [51, 43, 34, 20, 27, 18, 3, 8, 17, 10]. After…
- What is the minimum number of edges m such that EVERY simple undirected graph with 9 vertices and m edges is guaranteed to be connected?
- In the grid 01210 / 11111 / 11121 / 01111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…