This challenging quiz assesses knowledge of Binary Search Trees including insertion, deletion, search operations, as well as principles behind balanced BSTs like AVL and Red-Black Trees.
BST Insertion Properties
When inserting a new key into a binary search tree containing the values 7, 3, 15, and 10, which property ensures the correct placement of the new key?
- Each inserted key must be greater than all keys in the tree
- Each left child key is less than its parent and each right child key is greater
- All root-to-leaf paths must be the same length
- The tree has a maximum of two levels per branch
- Nodes must have unique values only when they are leaves
Deletion with Two Children
When deleting a node with two children in a binary search tree, which value is typically used to replace the deleted node's value?
- A random leaf node's value
- The post-order predecessor of the node
- The in-order successor of the node
- The level-order maximum of the left subtree
- The pre-order predecessor of the node
BST Search Performance
Given a completely unbalanced (degenerated) BST formed by inserting the sequence 1, 2, 3, 4, 5, what is the time complexity of searching for the value 5?
- Θ(log n)
- O(1)
- O(n^2)
- O(n)
- O(log log n)
AVL Tree Rotations
Suppose you insert keys 10, 20, and 30 (in that order) into an empty AVL tree; which rotation will be necessary to rebalance the tree?
- A double right-left rotation
- A single left rotation
- No rotation needed
- A double left-right rotation
- A single right rotation
AVL Balance Factor
In an AVL tree, what is the range of the balance factor allowed at every node to ensure height balance?
- 0, 1, or 2
- -1 or +1 only
- Any integer
- -2, -1, or 0
- -1, 0, or +1
Red-Black Tree Properties
Which is NOT a property of red-black trees among the following options?
- Every simple path from a node to its descendant leaves contains the same number of black nodes
- The root must always be black
- Red nodes may not have red children
- Every leaf (NIL) is black
- All left children must be black
Red-Black Tree Height Bound
If a red-black tree has n internal nodes, which statement best describes the worst-case height?
- Less than √n
- Exactly log₂n
- No more than 2 × log₂(n + 1)
- Exactly equal to n
- At least log₃n
BST Deletion Case Recognition
Given a node to delete in a BST where the node has only one child, what is the correct approach for removal?
- Recolor the child node black
- Swap the node with the leftmost node in the tree
- Replace the node with its sole child
- Leave the node but remove its child
- Increase the key by 1 and search again
AVL Tree Insertion Complexity
What is the worst-case time complexity for inserting a key into an AVL tree of n nodes?
- Θ(√n)
- O(log n log n)
- O(n)
- O(1)
- O(log n)
Red-Black Tree Color Flip Scenario
During an insertion into a red-black tree, when both the parent and parent’s sibling (uncle) are red, which operation must be performed first to maintain balance?
- Recolor the newly inserted node to black
- Single right rotation at the parent
- Double left-right rotation at the grandparent
- Recolor parent and uncle to black, grandparent to red
- Remove the parent node