Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Binary search trees

1.[2p]

The binary search tree property says that at every node x,

Correct
The answer is: every key in the left subtree is smaller than $x$ and every key in the right subtree is larger
The answer is: every key in the left subtree is smaller than $x$ and every key in the right subtree is larger
The answer is: every key in the left subtree is smaller than $x$ 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?

CorrectNot quite: 3

3.[2p]

Insert those same eight keys in ascending order instead. What is the height then?

CorrectNot quite: 7

4.[3p]

Deleting a node with two children works by

Correct
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.

Correct
The answer is: True

6.[3p]

For a million keys, an average successful search in a randomly built tree costs about 2lnn comparisons. How many is that?

CorrectNot quite: 27.6

7.[3p]

Which of these are reasons the degenerate linear tree matters in practice?

Select all that apply

Correct
Correct
Correct
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 h holding n keys.

  • Search for one key

  • Find the minimum

  • List every key in order

  • Insert a new key

  • O(h)

  • O(h)

  • O(h)

  • Θ(n)

Show the answer

Search for one key: O(h) Find the minimum: O(h) List every key in order: Θ(n) Insert a new key: O(h)

9.[3p]

Why is quicksort's average comparison count also the expected sum of node depths in a random tree?

Correct
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