B. The insert function does not assign returned nodes to root.left or root.right
C. The comparison operator should be <= instead of <
D. The function should return None at the end
Solution
Step 1: Analyze insert function behavior
Recursive calls to insert do not update root.left or root.right with returned nodes.
Step 2: Identify missing assignment
Without assigning, new nodes are created but not linked to the tree, so tree structure breaks.
Final Answer:
The insert function does not assign returned nodes to root.left or root.right -> Option B
Quick Check:
Missing assignment in recursion = bug [OK]
Hint: Always assign recursive insert results to child pointers. [OK]
Common Mistakes:
Ignoring returned node from recursive insert
Thinking base case is wrong
Changing comparison operator unnecessarily
5. You need to store a large dataset of user IDs with associated scores. You want to quickly find users by ID and also retrieve users sorted by their scores. Which combination of data structures is best?
hard
A. Use a Hash Map for ID lookup and a Balanced BST keyed by score for sorting
B. Use only a Hash Map keyed by score
C. Use only a BST keyed by user ID
D. Use a list sorted by user ID
Solution
Step 1: Identify requirements for fast lookup and sorted retrieval
Fast lookup by user ID suggests Hash Map; sorted retrieval by score suggests BST keyed by score.
Step 2: Evaluate options
Use a Hash Map for ID lookup and a Balanced BST keyed by score for sorting uses Hash Map for O(1) ID lookup and BST for ordered score retrieval, meeting both needs efficiently.
Final Answer:
Use a Hash Map for ID lookup and a Balanced BST keyed by score for sorting -> Option A
Quick Check:
Hash Map + BST combo = best for lookup + sorted data [OK]
Hint: Combine Hash Map for keys and BST for sorted order. [OK]
Common Mistakes:
Using only one data structure for both needs
Using list which is slow for lookup
Using BST keyed by ID only, ignoring score sorting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.