Test 2 Flashcards

1
Q

In a tree, relate number of external nodes to number of internal nodes

A

e = i + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In a tree, relate number of nodes to number of external nodes

A

n = 2e - 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In a tree, relate height to number of internal nodes

A

h ≤ i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a tree, relate height to total number of nodes

A

h ≤ (n - 1)/2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In a tree, relate number of external nodes to height

A

e ≤ 2h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a tree, logarithmically relate number of external nodes to height

A

log2e ≤ h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In a tree, logarithmically relate height to total number of nodes

A

h ≤ log2(n + 1) – 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In a tree, an internal node is…

A

A node with children. Also called a branch node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In a tree, an external node is…

A

A node without children. Also called a leaf node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the depth of a tree node? What is the height of a tree?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When do you skip indexes when representing a binary tree in an array?

A

When a node does not have children.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In an array-based binary tree, the left child is at the index…

A

2f(p) + 1 where f(p) is the current node’s index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In an array-based binary tree, the right child is at the index…

A

2f(p) + 2, where f(p) is the current node’s index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In an array-based binary tree, the parent is at the index…

A

⌊(f(p) – 1) / 2⌋, where f(p) is the current node’s index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In preorder traversal…

A

Visit node before children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In postorder traversal…

A

Visit children before node

17
Q

In inorder traversal (for a binary tree)…

A

Visit left child, then node, then right child

18
Q

In breadth-first traversal…

A

Initialize a queue to root node, and while the queue is not empty:
1. dequeue from the queue
2. visit the dequeued node
3. enqueue the children of the dequeued node.

19
Q

When searching for a key in a hash table…

A