Trees Flashcards

1
Q

Tree

A

An undirected graph that contains no cycles and is connected

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

Trees vs Graphs

A

Cycles: Graphs contain cycles, trees don’t
Connectivity: Graphs can be disconnected, trees are always connected
Hierarchy: Trees have a hierarchical structure, graphs don’t

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

Subtree

A

A tree who whose root is a node in another tree

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

Binary Trees

A

A rooted tree in which every parent has at most 2 children

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

Full Binary Tree

A

A binary tree in which each parent has exactly 2 children

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

Full m-ary tree

A

A tree in which each parent has exactly m children

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

If a full binary tree has n internal vertices, what is the formula to calculate the total vertices?

A

2n + 1

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

If a full m-ary tree has n internal vertices, what is the formula to calculate the total vertices?

A

mn + 1

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

How to calculate the number of leaves based on a tree’s height?

A

If h >= 0, then t <= 2^h

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

Pre-order Traversal

A
  1. Visit the root
  2. Pre-order (left subtree)
  3. Pre-order (right subtree)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In-order Traversal

A
  1. In-order (left subtree)
  2. Visit the root
  3. In-order (right subtree)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Post-order Traversal

A
  1. Post-order (left subtree)
  2. Post-order (right subtree)
  3. Visit the root
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Sorting trees rules

A

left child < parent
right child > parent

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

If left child = parent key then…

A

left child value < parent value

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

If right child value = parent key then…

A

right child value > parent value

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