Week 5 - AVL Tree Flashcards

(20 cards)

1
Q

What is an imbalanced Binary Search Tree (BST)?

A

An imbalanced BST is a tree where the left and right subtrees of some nodes differ significantly in height, leading to inefficient operations.

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

How does an imbalanced BST affect search operations?

A

In an imbalanced BST, search operations can degrade to O(n) time complexity, similar to a linked list, instead of the optimal O(log n).

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

What causes a BST to become imbalanced?

A

Inserting elements in sorted or nearly sorted order without balancing can cause one-sided growth, leading to imbalance.

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

Why is balancing a BST important?

A

Balancing ensures that the tree maintains minimal height, which keeps operations like search, insert, and delete efficient.

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

What is the concept of the height of a node in a binary tree?

A

The height of a node is the length of the longest path from that node to a leaf node. It is also the same as the height of the subtree rooted at that node.

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

What is the formula to calculate the balance factor in the binary tree?

A

BalanceFactor = Height of left subtree - Height of right subtree

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

How is the balance of a node defined in a binary tree?

A

balance (Empty) = 0

balance(Fork(X,L,R)) = height (L) - height (R)

This measures how balanced a node is by comparing the heights of its left and right subtrees.

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

What is an AVL Tree?

A

It is a self-balancing binary search tree. AVL (Adelson-Velsky and Landis) is where the balance factor at every node is -1, 0, or +1. This ensures the tree remains height-balanced.

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

What is a Perfectly Balanced Tree?

A

A Perfectly Balanced Tree is a binary tree in which all internal nodes have exactly two children and all leaf nodes are at the same level.

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

What is the relationship between the height (h) and the number of nodes (n) in an AVL Tree?

A

n grows exponentially as a function of h

h grows logarithmically as a function of n

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

What is the worst case of AVL tree?

A

n =F (h+2) - 1

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

What is the best case of AVL tree?

A

n = 2^h - 1

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

What is the range between best and worst case of AVL tree?

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

What is the formula for fibonacci numbers?

A

F(n) = F(n-1)+ F(n-2)

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

What is the minimum number of nodes in AVL?

A

N(h)=N(h−1)+N(h−2)+1

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

N(h) = F(n+2) -1

17
Q

What is the balance factor of each node in an AVL Tree?

A

it is -1, 0 or 1

18
Q

What are the two impacts found in AVL tree?

A
  1. Search: Same as BST, but the time complexity is O(log n)
  2. Insertion/deletion: It is possible to break the AVL invariant, need to rebalance the tree - Rotation
19
Q

How could we rebalance it without going
through all the nodes

A

Start with the lowest node with an imbalance!

20
Q

How many possible broken cases in generic cases?

A

With the constraint of AVL invariant, the new balance factor can only be -2 or 2.
- 4 possible cases