Tree-traversal Flashcards

1
Q

What are the 3 most common algorithms for traversing trees?

A

Pre-order, post-order and in-order

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

Define pre-order

A

Specifies the point in traversal where the node contents are processed

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

What happens to a node when it’s visited?

A

A nodes contents are outputted

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

How many times can a node be visited?

A

Multiple times but it’s contents can only be processed once

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

What makes pre-order traversal special?

A

Each node is visited before the algorithm traverses either of the nodes subtrees

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

State the simplified recursive algorithm for a left-right pre-order traversal

A

Visit the node
Pre-order traverse of nodes left sub tree
pre-order traverse of the nodes right subtree

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

What happens in an in-order traversal?

A

Each node is visited between each of it’s subtrees

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

State the simplified algorithm for a left-right in-order traversal

A

Do an in-order traversal of the whole left subtree
visit the node
in-order traverse the right subtree

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

What happens in a post-order traversal?

A

Each node is visited after both of it’s subtrees

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

State the simplified recursive algorithm for a left-right post-order traversal

A

Do a post-order traversal of the left subtree
Do a post-order traversal of the right subtree
Visit the node

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