Self-Assessment Quiz: Trees

Twenty questions to check your understanding. Answer before opening the key. Aim for 16+.


Question 1

A tree is defined as a graph that is:

A) connected and may contain cycles B) connected and acyclic C) acyclic but possibly disconnected D) any graph with $n - 1$ edges

Question 2

A tree has 23 vertices. Exactly how many edges does it have?

A) 22 B) 23 C) 24 D) cannot be determined without more information

Question 3

Which of the following is not an equivalent characterization of a tree (Theorem 31.1)?

A) there is exactly one path between every pair of vertices B) it is connected, and removing any edge disconnects it C) it is acyclic, and adding any edge between non-adjacent vertices creates a cycle D) every vertex has degree at most 2

Question 4

In a rooted tree, the depth of a vertex is measured:

A) up from the deepest leaf B) down from the root (the root has depth 0) C) as the number of its children D) as the number of its descendants

Question 5

The height of a rooted tree equals:

A) the number of leaves B) the depth of the root C) the maximum depth over all vertices D) the number of internal nodes

Question 6

Which traversal of a binary search tree visits the keys in sorted (increasing) order?

A) preorder B) inorder C) postorder D) level-order

Question 7

You want to free (deallocate) every node of a binary tree in C. Which traversal must you use?

A) preorder B) inorder C) postorder D) any order works

Question 8

For the binary tree Node(1, Node(2), Node(3)), the preorder traversal is:

A) $[2, 1, 3]$ B) $[1, 2, 3]$ C) $[2, 3, 1]$ D) $[3, 2, 1]$

Question 9

A binary search tree operation (search/insert) costs $O(h)$, where $h$ is the height. For a BST that has become a degenerate stick on $n$ keys, a search costs:

A) $O(1)$ B) $O(\log n)$ C) $O(n)$ D) $O(n \log n)$

Question 10

Which insertion order turns a binary search tree into a degenerate $O(n)$ stick?

A) a random permutation of the keys B) the keys in already-sorted order C) inserting the median first D) any order produces the same shape

Question 11

In an array-backed binary heap with the root at index 0, the parent of the node at index $i$ (for $i \ge 1$) is at index:

A) $2i + 1$ B) $2i + 2$ C) $\lfloor (i-1)/2 \rfloor$ D) $i - 1$

Question 12

A (min-) heap is a complete binary tree in which:

A) the left subtree's keys are all smaller than the right subtree's B) every node's key is $\le$ both of its children's keys C) the keys are stored in sorted order by index D) every internal node has exactly two children

Question 13

The postfix (Reverse Polish) form of an expression is produced by which traversal of its expression tree?

A) preorder B) inorder C) postorder D) level-order

Question 14

A trie lookup of a string of length $m$ takes time:

A) $O(\log N)$ where $N$ is the number of stored words B) $O(N)$ C) $O(m)$, independent of the number of stored words D) $O(m \cdot N)$

Question 15

In a prefix code represented as a binary tree, the symbols sit at:

A) the root only B) internal nodes C) leaves only D) any nodes, as long as no two share a depth

Question 16

Huffman's algorithm repeatedly merges:

A) the two trees of largest frequency B) the two trees of smallest frequency C) the leftmost two trees in insertion order D) a random pair of trees

Question 17 (True/False, justify)

True or false: A graph that is acyclic and has exactly $n - 1$ edges must be connected (hence a tree). Justify in one sentence.

Question 18 (True/False, justify)

True or false: Knowing only the inorder traversal of a binary tree is enough to reconstruct the tree uniquely. Justify in one sentence.

Question 19 (Short answer)

State the proof technique used to show "a tree on $n$ vertices has exactly $n - 1$ edges," and name the single creative step that makes the induction work.

Question 20 (Short answer)

In one sentence, explain why a symbol must never be placed at an internal node of a prefix-code tree.


Answer Key

Q Ans Note
1 B Tree = connected + acyclic; everything else follows.
2 A Theorem 31.2: a tree on $n$ vertices has exactly $n - 1 = 22$ edges.
3 D Bounded degree is not a tree characterization (a path has max degree 2 but so do many non-trees / non-graphs); D is false.
4 B Depth is measured down from the root; the root has depth 0.
5 C Height = maximum depth = length of the longest root-to-leaf path.
6 B Inorder: left subtree (smaller) → node → right subtree (larger).
7 C Postorder frees both children before the parent; preorder would orphan them.
8 B Preorder visits the root first: $1$, then left $2$, then right $3$.
9 C A stick has height $h \approx n - 1$, and cost is $O(h) = O(n)$.
10 B Sorted input always attaches on the same side, building a single chain.
11 C Parent index is $\lfloor (i-1)/2 \rfloor$; children are $2i+1$, $2i+2$.
12 B The heap property relates each node only to its children.
13 C Postorder = children then node = postfix / RPN.
14 C You follow one edge per character: $O(m)$, regardless of dictionary size.
15 C Symbols at leaves ⟺ no codeword is a prefix of another.
16 B Greedy: merge the two smallest frequencies so the rarest sit deepest.
17 True An acyclic graph on $n$ vertices with $c$ components has $n - c$ edges (Ex. 31.7); $n - 1$ edges forces $c = 1$, i.e. connected.
18 False Inorder alone is ambiguous; you need inorder plus preorder (or postorder) to reconstruct a binary tree uniquely.
19 Induction on the number of vertices; the creative step is "find a leaf, remove it (and its edge), apply the hypothesis to the smaller tree."
20 Its codeword would be a prefix of every codeword in the subtree below it, breaking prefix-freeness and making decoding ambiguous.

Topics to review by question

Questions Topic
1, 3 Definition and equivalent characterizations of a tree (§31.1)
2, 17, 19 The $n - 1$ edge-count theorem and its proof (§31.1)
4, 5 Rooted-tree terminology: depth vs. height (§31.2)
6, 7, 8, 13, 18 Binary-tree traversals and what each is for (§31.3)
9, 10 BST performance and the height story (§31.4)
11, 12 Binary heaps and array indexing (§31.5)
14 Tries and prefix queries (§31.5)
15, 16, 20 Prefix codes and Huffman coding (§31.6)