CSC 230 (5) - Balanced Binary Trees

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

28 Terms

1
New cards

What is a Balanced Binary Tree?

A tree that maintains height balance to ensure efficient operations.

2
New cards

Why is a balanced tree always a valid BST?

Because it inherently maintains the ordering property of a BST (left < parent < right).

3
New cards

Why are balanced trees important?

They keep tree height small, ensuring search, insert, and delete operations remain efficient.

4
New cards

How is tree height calculated?

The number of edges (or levels) on the longest path from the root to a leaf.

5
New cards

What is a node’s balance factor?

Height(left subtree) − Height(right subtree).

6
New cards

What are the only valid balance factor values in an AVL Tree?

-1, 0, or 1

7
New cards

What is the AVL Tree rule for balance?

The heights of any node’s left and right subtrees differ by at most 1.

8
New cards

When is an AVL Tree considered unbalanced?

When a node’s balance factor is greater than 1 or less than −1.

9
New cards

What is a Red-Black Tree?

A self-balancing BST where each node is colored red or black and follows specific balancing rules.

10
New cards

Red-Black Tree Rule 1 (Red/Black Property)?

Every node is colored either red or black.

11
New cards

Red-Black Tree Rule 2 (Root Property)?

The root node is always black.

12
New cards

Red-Black Tree Rule 3 (Leaf Property)?

Every null leaf (NIL) is black.

13
New cards

Red-Black Tree Rule 4 (Red Property)?

If a node is red, then both of its children must be black.

14
New cards

Red-Black Tree Rule 5 (Depth Property)?

For each node, every path from that node to a descendant leaf contains the same number of black nodes.

15
New cards

Which STL containers are implemented using Red-Black Trees?

std::map and std::set.

16
New cards

In std::map and std::set, what are the tree elements?

The keys.

17
New cards

What is a tree rotation?

A local restructuring operation used to restore balance in a balanced BST.

18
New cards

What is a left rotation?

A rotation that moves the right child up and the pivot node down to the left.

19
New cards

What is a right rotation?

A rotation that moves the left child up and the pivot node down to the right.

20
New cards

What is the Left-Left (LL) case in AVL trees?

Left subtree of the left child is heavy → perform a right rotation on the pivot.

21
New cards

What is the Right-Right (RR) case in AVL trees?

Right subtree of the right child is heavy → perform a left rotation on the pivot.

22
New cards

What is the Left-Right (LR) case in AVL trees?

Left rotate the pivot’s left child, then right rotate the pivot.

23
New cards

What is the Right-Left (RL) case in AVL trees?

Right rotate the pivot’s right child, then left rotate the pivot.

24
New cards

What are the steps of the AVL insertion algorithm?

  1. Insert the node using the standard BST insertion algorithm

  2. Traverse back up to the root and rebalance using rotations

25
New cards

What are the steps of the AVL removal algorithm?

  1. Remove the node using the standard BST removal algorithm

  2. Rebalance ancestors from the parent of the removed node up to the root

26
New cards

How is a node rebalanced during AVL removal?

Compute the balance factor and perform rotations if the factor is greater than 1 or less than −1.

27
New cards

Key difference between AVL and Red-Black Trees?

AVL trees enforce strict balance (−1, 0, 1), while Red-Black trees enforce balance through coloring rules.

28
New cards

Now, do problem set 09 and quiz 10 and quiz 11