Trees Flashcards

1
Q

What are the three classes of binary trees?

A

Complete
Full
Perfect

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

What makes a binary tree complete?

A

Every level has two children per node. The last level can be an exception to this, but if not fully filled it has to be filled left to right.

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

What makes a binary tree full?

A

Every node must have zero or two children. So there cannot be any nodes with only one child.

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

What are the three orders of traversal for binary trees?

A

In order.
Pre order
Post order

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

Explain in order reversal.

A

Visit left child.
Visit the current node.
Visit right child.
If you were printing out as you were visiting you would get an in ascending list of items from a binary search tree. (Least to greatest)

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

Explain pre order reversal.

A

Visit the current
Visit the left
Visit the right.

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

Explain post order traversal

A

Visit left
Visit right
Visit current

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

What are the two most common ways to search a graph?

A

BFS - Breadth first search

DFS - Depth first search

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

What is generally a reason to prefer BFS?

A

Looking for shortest path, don’t necessarily care about visiting all the nodes.

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

What is generally a reason to prefer DFS?

A

You know your want to visit every node.

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

What is the general strategy to implement DFS?

A

Recursion.

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

What is general strategy to implement BFS?

A

Enqueue the given node. While your queue is not empty, deque a node to visit, and enqueue it’s children/neighbors.

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