Question 41
MediumWhich traversal of a BST gives the keys in decreasing order?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
Which traversal of a BST gives the keys in decreasing order?
Preorder
Postorder
Reverse inorder (right, root, left)
Level order
Sign up free to see the answer and a step-by-step explanation.
What is the average-case height of a BST built from n keys inserted in random order?
O(1)
O(√n)
O(log n)
O(n)
Sign up free to see the answer and a step-by-step explanation.
Which preorder sequence could be from a BST?
10, 40, 5, 50, 1, 7
10, 50, 5, 40, 1, 7
10, 5, 40, 1, 7, 50
10, 5, 1, 7, 40, 50
Sign up free to see the answer and a step-by-step explanation.
An AVL tree has the left subtree height 3 and right subtree height 1 at some node. What happens?
The tree is rebuilt from scratch
The node is deleted
Nothing; it is balanced
The node is unbalanced (factor 2) and a rotation is done
Sign up free to see the answer and a step-by-step explanation.
Inserting 10, 20, 30 into an empty AVL tree causes which rotation?
No rotation
A single right rotation at 30
A left-right rotation
A single left rotation at 10
Sign up free to see the answer and a step-by-step explanation.
An AVL tree receives the keys 30, then 10, then 20. Which rebalancing step is needed after the third insertion?
No rotation
Left-right (double) rotation
Single left rotation
Single right rotation
Sign up free to see the answer and a step-by-step explanation.
What is the minimum number of nodes in an AVL tree of height 4 (height of a single node = 1)?
15
8
7
4
Sign up free to see the answer and a step-by-step explanation.
Which balanced tree is used by C++ std::map and Java TreeMap?
Red-black tree
B tree
Splay tree
AVL tree
Sign up free to see the answer and a step-by-step explanation.
Why might an AVL tree be preferred over a red-black tree?
AVL trees need no rotations
Red-black trees are unbalanced
AVL trees use less memory always
For lookup-heavy workloads, since AVL trees are more strictly balanced
Sign up free to see the answer and a step-by-step explanation.
How can you find the inorder successor of a node with a right child in a BST?
Go to the root
Go to the right child, then as far left as possible
Go to the left child
Go to the parent
Sign up free to see the answer and a step-by-step explanation.