Data Structures AVL and Binary Search Trees

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 12

flashcard set

Earn XP

Description and Tags

continue from last week

13 Terms

1

AVL Tree

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

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

New cards
2

Balance of every node should be between

-1, 0 or 1

New cards
3

AVL is o(___)

log n

New cards
4

height of an empty tree is equal to

0

New cards
5

operations on AVL Trees

Search, Insert and Delete

New cards
6

Insert

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

New cards
7

Types of rotation

Left and right rotation


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

New cards
8

Good insert case

Balanced Preserved (insert middle then small then tall)

New cards
9

Bad Insert Case

Left left right or right right imbalance

New cards
10

how to fix left left inbalance

using right right insertion

New cards
11

Bad Insert case #2

Left right or Right Left

New cards
12

To fix RL or LR we fix it using

Double Rotation

New cards
13

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!)

New cards
robot