tree_flashcards

1
Q

What is a leaf node in a tree?

A

A node that has no children

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

What is a root node in a tree?

A

The top node in a tree that has no parent

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

What are siblings in a tree?

A

Nodes that share the same parent node

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

What are cousins in a tree?

A

Nodes that have parents who are siblings

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

What is the level/depth of a node?

A

The number of edges from the root to that node

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

`What is the height of a tree?

A

The number of edges in the longest path from root to any leaf

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

What is the degree of a node?

A

The number of children that node has

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

What is an edge in a tree?

A

The connection between two nodes

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

What is inorder traversal?

A

Visit left subtree, then root, then right subtree (LNR)

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

What is preorder traversal?

A

Visit root, then left subtree, then right subtree (NLR)

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

What is postorder traversal?

A

Visit left subtree, then right subtree, then root (LRN)

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

What is level-order traversal?

A

Visit nodes level by level, left to right

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

What makes a valid Binary Search Tree (BST)?

A

For every node: all values in left subtree are less than node’s value and all values in right subtree are greater

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

What makes a tree balanced?

A

the heights of left and right subtrees of any node differ by at most one (-1, 0, 1)

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

What is an AVL tree?

A

A self-balancing BST where heights of left and right subtrees differ by at most one for all nodes

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

What is the balance factor in an AVL tree?

A

The difference between the height of the right subtree and the left subtree (left subtree - right subtree)

17
Q

What is the time complexity for searching in a balanced BST?

A

O(log n)

18
Q

What is the time complexity for searching in an unbalanced BST (worst case)?

A

O(n)

19
Q

What is the primary advantage of AVL trees?

A

Guaranteed O(log n) performance for all operations (search, delete, add)

20
Q

What is the main disadvantage of AVL trees?

A

Extra memory for balance factors and computational overhead for rebalancing after modifications

21
Q

What is a rotation in AVL trees?

A

A balancing operation that changes the structure of the tree while maintaining BST properties

22
Q

What is a perfect binary tree?

A

A binary tree where all interior nodes have two children and all leaves are at the same level

23
Q

What is a complete binary tree?

A

A binary tree where all levels except possibly the last are completely filled

24
Q

What is a full binary tree?

A

A binary tree where every node has either 0 or 2 children (no nodes have only one child)

25
Q

Why do we care about the shape of a tree?

A

The shape of a tree directly impacts its performance - a balanced tree ensures O(log n) operations, while an unbalanced/skewed tree can degrade to O(n) performance, essentially becoming as slow as a linked list. This affects all operations including searching, insertion, and deletion.