Binary search trees
1.[2p] The binary search tree property says that at every node ,
The binary search tree property says that at every node ,
The answer is: every key in the left subtree is smaller than and every key in the right subtree is larger
The answer is: every key in the left subtree is smaller than and every key in the right subtree is larger
The answer is: every key in the left subtree is smaller than and every key in the right subtree is larger
2.[3p] Insert 41, 23, 67, 12, 35, 55, 88, 29 in that order. What is the height of the resulting tree, counting edges?
Insert 41, 23, 67, 12, 35, 55, 88, 29 in that order. What is the height of the resulting tree, counting edges?
3.[2p] Insert those same eight keys in ascending order instead. What is the height then?
Insert those same eight keys in ascending order instead. What is the height then?
4.[3p] Deleting a node with two children works by
Deleting a node with two children works by
The answer is: overwriting its key with its successor's, then deleting the successor node, which has no left child
The answer is: overwriting its key with its successor's, then deleting the successor node, which has no left child
The answer is: overwriting its key with its successor's, then deleting the successor node, which has no left child
5.[1p] An in-order traversal of a binary search tree emits its keys in ascending order.
An in-order traversal of a binary search tree emits its keys in ascending order.
The answer is: True
6.[3p] For a million keys, an average successful search in a randomly built tree costs about comparisons. How many is that?
For a million keys, an average successful search in a randomly built tree costs about comparisons. How many is that?
7.[3p] Which of these are reasons the degenerate linear tree matters in practice?
Which of these are reasons the degenerate linear tree matters in practice?
Select all that apply
The answer is: Identifiers assigned by an incrementing counter arrive in ascending order, Rebuilding a tree from a sorted export inserts every key in order, An attacker who controls insertion order can force it deliberately
8.[3p] Match each operation to what it costs in a binary search tree of height holding keys.
Match each operation to what it costs in a binary search tree of height holding keys.
Search for one key
Find the minimum
List every key in order
Insert a new key
Show the answer
Search for one key: Find the minimum: List every key in order: Insert a new key:
9.[3p] Why is quicksort's average comparison count also the expected sum of node depths in a random tree?
Why is quicksort's average comparison count also the expected sum of node depths in a random tree?
The answer is: The first pivot is the root and each partition is a subtree, so the two counts are the same quantity
The answer is: The first pivot is the root and each partition is a subtree, so the two counts are the same quantity
The answer is: The first pivot is the root and each partition is a subtree, so the two counts are the same quantity