Data Structures · Question 28 · Hard
Data Structures question 28
The keys 10, 20, 30, 25, 28 are inserted in that order into an empty AVL tree, with rebalancing after each insertion. What is the preorder traversal of the final tree?
- 25 20 10 28 30
- 20 10 25 30 28
- 20 10 28 25 30
- 20 10 30 25 28
Answer and explanation
Answer: C. 20 10 28 25 30
Explanation: Inserting 30 causes a left rotation, making 20 the root with children 10 and 30. 25 goes left of 30, then 28 goes right of 25, unbalancing 30 (left-right case). A double rotation makes 28 the parent of 25 and 30, so preorder is 20 10 28 25 30.
Previous: A binary tree has preorder traversal A B D E H C F G and inorder traversal D B… · Next: The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may…
Practise data structures
Try a fresh set of data structures questions with an explanation after every answer, free and without signing up: Data Structures practice. Or sit a full placement mock test.
More data structures questions
- In a doubly linked list, you are given a pointer to a node (not the head or…
- An array-based binary min-heap holds [2, 5, 3, 9, 6, 4, 8]. One deleteMin…
- A binary tree has preorder traversal A B D E H C F G and inorder traversal D B…
- The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may…
- A max-heap of 15 distinct keys is stored in array positions 1 to 15. How many…
More technical & programming practice
Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge