Data Structures AVL and Binary Search Trees

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

flashcard set

Earn XP

Description and Tags

continue from last week

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards

AVL Tree

BST in which every node is balanced, right heavy or left heavy.

Balance = height(left subtree) - height(right subtree)

2
New cards

Balance of every node should be between

-1, 0 or 1

3
New cards

AVL is o(___)

log n

4
New cards

height of an empty tree is equal to

0

5
New cards

operations on AVL Trees

Search, Insert and Delete

6
New cards

Insert

Do a TreeInsert as in BST, then verify if its still an AVL. If it’s unbalanced, we need to rebalance.

7
New cards

Types of rotation

Left and right rotation


Left rotation: Height of left subtree inc, height of right dec, BST order maintained

8
New cards

Good insert case

Balanced Preserved (insert middle then small then tall)

9
New cards

Bad Insert Case

Left left right or right right imbalance

10
New cards

how to fix left left inbalance

using right right insertion

11
New cards

Bad Insert case #2

Left right or Right Left

12
New cards

To fix RL or LR we fix it using

Double Rotation

13
New cards

AVL Insert Alg

  1. Find spot for value

  2. Hang new node
    • Search back up looking for imbalance
    • If there is an imbalance:
    case #1: Perform single rotation
    case #2: Perform double rotation
    • Done!
    (There can only be one imbalance!)