Test 2 Flashcards
In a tree, relate number of external nodes to number of internal nodes
e = i + 1
In a tree, relate number of nodes to number of external nodes
n = 2e - 1
In a tree, relate height to number of internal nodes
h ≤ i
In a tree, relate height to total number of nodes
h ≤ (n - 1)/2
In a tree, relate number of external nodes to height
e ≤ 2h
In a tree, logarithmically relate number of external nodes to height
log2e ≤ h
In a tree, logarithmically relate height to total number of nodes
h ≤ log2(n + 1) – 1
In a tree, an internal node is…
A node with children. Also called a branch node.
In a tree, an external node is…
A node without children. Also called a leaf node.
What is the depth of a tree node? What is the height of a tree?
Depth of a node is the number of ancestors; height is the maximum depth and the number of levels minus one (because the root doesn’t have an ancestor).
When do you skip indexes when representing a binary tree in an array?
When a node does not have children.
In an array-based binary tree, the left child is at the index…
2f(p) + 1 where f(p) is the current node’s index
In an array-based binary tree, the right child is at the index…
2f(p) + 2, where f(p) is the current node’s index
In an array-based binary tree, the parent is at the index…
⌊(f(p) – 1) / 2⌋, where f(p) is the current node’s index
In preorder traversal…
Visit node before children