AVL Tree - PowerPoint PPT Presentation

About This Presentation
Title:

AVL Tree

Description:

Title: AVL Tree Author: dpu Last modified by: Skul 089-530-7637 Created Date: 1/18/2005 3:31:44 AM Document presentation format ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 21
Provided by: dpu49
Category:
Tags: avl | tree

less

Transcript and Presenter's Notes

Title: AVL Tree


1
AVL Tree
  • ????????????? Binary Tree ???????????? (Balance)
    ????????????????? Subtree ??????????????????
  • ?????? Tree ??????????????? Root ??? Tree
    ?????????????????????

2
AVL Tree (Adelson-Velskii and Landis)
  • ???? Binary Search Tree ??????????????????????????
    ??????? (Balance Condition)
  • Depth ??? Tree ???? O(Log N)
  • ??? Height ??? Subtree ???????????????????????????
    ???????? 1

h 2
h 0
3
AVL Tree Operations
  • ?????????????? AVL Tree ?????????????? O(Log N)
  • ??? Insert ??????????????????????? Update ?????
    Balance ??? Node ??? Node ????????? path
    ????????? Root
  • ??? Update ??? Balance ??? Tree
    ???????????????Rotation (???????)
  • Single Rotation
  • Double Rotation

4
AVL Tree Rotation
  • ni ???? Node ?????????????????????????????
    Rebalance ???????????????????????????? Tree
    ???????????? 4 ????
  • LL Insert into left subtree of the left child

4
2
1
5
AVL Tree Rotation
  • RR Insert into right subtree of the right child

4
6
7
6
AVL Tree Rotation
  • LR Insert into right subtree of the left
    subtree of the node

8
4
6
5
7
AVL Tree Rotation
  • RL Insert into left subtree of the right
    subtree of the node

8
12
10
11
8
Single Rotation
  • ?????? LL ??? RR ??? Insert ??????????????
    (Outside) ??? Tree (????-????, ???-???)
  • Rebalance ??????? Single Rotation

LL Insert ??? X ????? k2 ?????????
9
Single Rotation
  • RR - Insert ??? Z ????? k1 ?????????

10
  • Node 23 ????? subtree ??????????? 16 ?? height 2
    ?????? subtree ?????????? 16 ?? height 0
  • Rebalance Node 16 ???? Single Rotation

11
  • ????? insert ??? 5, 6 ??? 7 ???? ????? subtree
    ??????????? 5 ?? height2 ?????? subtree
    ????????? height0
  • Rebalance Node 5 ???? Single Rotation

12
  • insert key 8, 9 ???? ????? subtree ?????????? 7
    ?? height2 ?????? subtree ?????????? height0
  • Rebalance Node 7 ???? Single Rotation

13
  • ????? insert key 4, 3 ???? ????? subtree
    ?????????? 5 ?? height2 ?????? subtree
    ?????????? height 0
  • Rebalance Node 5 ???? Single Rotation

14
Double Rotation
  • ?????? LR ??? RL ??? Insert ????????????????
    (Inside) ??? Tree (????-???, ???-????)
  • Rebalance ??????? Double Rotation

LR Insert ??? X ????? k2 ????????? Single
Rotation ???????? k1 ?????????
15
Double Rotation
  • Left-Right Double Rotaion ???????? LR

16
Double Rotation
  • Right-Left Double Rotaion ???????? RL

17
  • insert Key 1 ??? 2 ?????? ????????? Rebalance 3
    (LR)
  • Rebalance 7 ???? Double Rotations

18
  • Insert Key 14, 15 ?????? ????????? Rebalance 9
    (RR)
  • Rebalance 9 ???? Single Rotations

19
  • Insert Key 10 ?????? ????????? Rebalance 8 (RL)
  • Rebalance 8 ???? Double Rotation

20
  • Insert Key 11, 12 ?????? ????????? Rebalance 10
    (RR)
  • Rebalance 10 ???? Single Rotations
Write a Comment
User Comments (0)
About PowerShow.com