Download presentation
Presentation is loading. Please wait.
Published byHarjanti Sutedja Modified over 6 years ago
1
Tree Lecturers : Boontee Kruatrachue Room no Kritawan Siriboon Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley
2
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
3
Height of node = longest path length from node to leaf
Leaf Height = 0 Empty Tree Height = -1 Tree Height = Root Heigth r 5 A 4 B C 3 D 3 E F G H 2 2 I J K L 1 1 M N O = Longest Leaf from C O P P = Longest Leaf from A
4
Why Balanced Tree ? Tree Efficiency (searching, inserting, deleting,...) → O(Height) Binary Search Tree sometimes turn degenerated 6 3 1 4 2 7 5 Linear Linked list or near Linear Search O(n) → Binary Search Tree → (Perfect) Balanced Tree O(log2n) Every leaf is at the same level (very rear case) Balanced Binary Search Tree Non-Height Balanced / \ - // Height Balanced 5 1 8 7 2 4 3 → Hight Balanced Tree O(log2n) → AVL log2n Every node’s subtrees’ heights differ <= 1
5
Every node’s balance factor = 0
Height Balanced Tree : Every node’s subtrees’ heights differ <= 1 (Nearly Balanced) Balance factor of every node is 0 or 1 or -1 Balance factor of a node : different of left & right subtrees’ hights = Height(Left Subtree) – Height(Right Subtree) - / Height Balanced - Height Balanced Every node’s balance factor = 0 - \ / Height Balanced 1 0-(-1) 1 0-(-1) -1 -1-0 - / \ // Non - Height Balanced 2 1-(-1) -1 1-2 1 0-(-1) -1-0
6
AVL (Height Balanced) Tree
AVLTree Self- rebalancing binary search tree to keep height balance. Maximum height <= 1.44 log2n : near the ideal complete binary tree. Search, insertion, deletion ( both average & worst cases) O(log2n) Insertions & deletions may require 1 or > 3 rotations. Worst case not much slower than random binary search tree. Adelson-Velskii Landis (1962 Soviet inventors) 5 1 8 7 2 4 3 \ / - Height Balanced Smallest AVL tree of height 9 Bad Binary Tree Balance at root is not enough. - / /// // \ \\\ \\ Non-Height Balanced / \ - //
7
Searching in AVL = Searching in BST
AVL is a binary search tree. Review Searching a BST (Binary Search Tree). Compare search key against key in node start from root. Follow associated link (recursively). Left link if search key < key in node Right link if search key ≥ key in node Ex. Search for 3 3 < 5 3 1 4 7 9 2 8 5 3 ≥ 2 3 < 4 found 3
8
Review Inserting in BST
Search to bottom for key. / - 1 7 9 2 8 5 Ex. Insert 3 Ex. Insert 6 1 7 9 2 8 5 / - / - 1 7 9 2 8 5 is NULL Not found 3 is NULL Not found 6
9
Review Inserting in BST
Search to bottom for key. / - 1 7 9 2 8 5 NULL Ex. Insert 3 Ex. ert 6 / - 1 7 9 2 8 5 / - 1 7 9 2 8 5 Not found 3 Not found 6
10
Review Inserting in BST
Search to bottom for key. Insert node as a new leaf node. / - 1 7 9 2 8 5 NULL Ex. Insert 3 Ex. Insert 6 3 / - 1 7 9 2 8 5 / - 1 7 9 2 8 5 6 Not found 3 Insert 3 as a new leaf Not found 6 Insert 6 as a new laef -
11
Inserting in AVL without Rebalancing
1 7 9 2 8 5 / - h = 1 h =-1 h = 2 h = 0 Inserting at short side or equal side → AVL ‘s still height balanced Insert BST new leaf node. Inserting node will change the height of some nodes (increase by 1) Change balance factors along the path to the root. 3 Short Side Equal Side 6 Long Side on the path from the newly inserted node to the root only. Ex. Insert 3 at short side. Ex. Insert 6 at equal side. insert 3 at short side still height balance - 1 7 9 2 8 5 1 7 9 2 8 5 / - insert 6 at equal side still height balance - - \ / 3 6
12
Insertion Re-balancing in AVL
h = 4 10 30 45 55 20 50 65 75 87 40 70 85 95 90 60 80 h = 1 Short Side / \ - h = 3 h = 0 h = 2 x 1st unbalanced x Insert 15 h = 1 10 30 45 55 20 50 65 75 87 40 70 85 95 90 60 80 h = 2 Short Side / \ - h = 4 h = 0 h = 3 h = 5 // / \ - Hight diff = 2 Long Side Long Side 15 5 15 25 35 43 46 52 57 Height Unbalanced → no longer AVL ! Height balanced again→ AVL 20 40 60 80 h = 2 - / 90 87 85 95 \ 65 75 70 h = 1 45 55 50 10 30 h = 0 15 x y z Re-balance Inserting AVL in a long side. Causes some node(s) unbalanced (height diff = 2) only up the inserted path. x = 1st unbalanced node Need rebalancing the (blue) shaded subtree. Rebalancing does not change : height of the subtree → ie. Nor height of root. → Only some part of the shaded subtree’s balance facters need changing. h = 4 h = 3
13
4 Insertion Re-balancing in AVL
10 30 20 65 75 87 40 70 85 95 90 60 80 5 15 25 35 - \ / 45 55 50 43 46 52 57 x Short Side Long Side 65 55 60 25 15 7 50 20 5 1 3 30 10 70 62 59 51 - \ 45 35 40 46 41 37 32 x Short Side Long Side 1. Left_Left 2. Right_Left 4. Left_Right 3. Right_Right Inserting AVL in a long side. x = 1st unbalanced node , inserted node is at 1. left subtree of left son of x 2. right subtree of left son of x 3. right subtree of right son of x 4. left subtree of right son of x z y x z y x left son of x left son of x z y x z y x right son of x right son of x
14
Rebalancing Left Subtree of Left Son of x (1st Unbalanced Node)
1st unbalanced x son of y : z son of x : y T0 T2 T3 10 30 45 55 20 50 65 75 87 40 70 85 95 90 60 80 h = 2 Short Side // / \ - h = 4 h = 1 h = 0 h = 3 h = 5 T1 h = 4 10 30 45 55 20 50 65 75 87 40 70 85 95 90 60 80 5 15 25 35 h = 1 Short Side / \ - h = 3 h = 0 43 46 52 57 Long Side h = 2 x Height Unbalanced → no longer AVL ! hight diff = 2 Insert 15 Long Side 15 x = 1st unbalanced node. Along the path, let y = son of x, z = son of y. Left subtree of left son of x Right rotate at x x down to be y’s (right) son. y up to replace x’ s place : be son of x’s father. Re-arrange T0,T1,T2,T3 to preserve the properties of BST. T0 ≤ z ≤ T1 ≤ y ≤ T2 ≤ x ≤ T3 Fixing some part of the shaded subtree’s balance facters. Height of the blue shaded subtree doesn’t change -> also the whole AVL‘s. h = 3 h = 4 80 / 90 87 85 95 \ - Re-balance 20 40 60 x y z h = 2 T0 10 30 h = 1 - T1 15 h = 0 - \ / T2 45 55 50 - h = 1 T3 65 75 70 - h = 1 Height balanced again→ AVL
15
Proof : Rebalancing Area’ Height’s unchange (Left Subtree of Left son of x)
Insert at a long side T0 x = 1st unbalanced node, y = son of x, z = son of y height(T1) = ? When height(T0) = h. = h-1 or h ∵ heightDiff (T0,T1 ) ≤1 & ≠ h+1 ∵ T1 : short side, T0 : long side = h ∵ After inserting , z : balanced ∴ heightDiff ≤1 height(T2) = h+1 ∵ After inserting , y : balanced height(T3) = h+1 ∵ After inserting , x : unbalanced z y x T1 T2 T3 T0 h+3 h+2 ? h+1 h Rebalancing does not change heights of the subtree → ie. Nor of root. So only fix balance facters of inserted path to y and of x. Long Side h+3 h h+1 h+2 h-1/h h+1/h+2 - / Insert at T0 z y x T1 T2 T3 T0 h+4 h/h+1 // 1st unbalanced 1st Diff > 1 balanced H.Diff ≤1 Right Rotate at x Long Side
16
Proof : Rebalancing Area’ Height’s unchange (Left Subtree of Left son of x)2
Insert at a long side T1 x = 1st unbalanced node, y = son of x, z = son of y height(T0) = ? When height(T1) = h. = h-1 or h ∵ heightDiff (T0,T1 ) ≤1 & ≠ h+1 ∵ T0 : short side, T1 : long side = h ∵ After inserting , z : balanced ∴ heightDiff ≤1 height(T2) = h+1 ∵ After inserting , y : balanced height(T3) = h+1 ∵ After inserting , x : unbalanced h h+1 h+2 h+3 ? z y x T1 T2 T3 T0 Rebalancing does not change heights of the subtree → ie. Nor of root. So only fix balance facters of inserted path to y and of x. Long Side z y x T1 T2 T3 T0 h+1 h+2 h+3 h+4 h 1st unbalanced balanced \ / // - 1st Diff > 1 H.Diff ≤1 Right Rotate at x Insert at T1 h-1/h h/h+1 h+1/h+2 Long Side
17
4 Kinds of Rebalancing in AVL
x = 1st unbalanced node, y = son of x, z = son of y Left subtree of left son of x 2. Right subtree of left son of x 2 z y x T1 T2 T3 T0 or z y T1 T0 x T3 T2 or z y x T2 T0 T3 T1 or y z T1 T0 x T3 T2 or 1 3. Right subtree of right son of x 4. Left subtree of right son of x 2 z y x T2 T1 T0 T3 or z y T2 T3 x T0 T1 or z y x T1 T3 T0 T2 or y z T2 T3 x T0 T1 or 1
18
Proof : Rebalancing Area’ Height’s unchange (Right Subtree of Left son of x)
Insert at a long side T1 x = 1st unbalanced node, y = son of x, z = son of y height(T2) = ? When height(T1) = h. = h-1 or h ∵ heightDiff (T2,T1) ≤1 & ≠ h+1 ∵ T2 : short side, T1 : long side = h ∵ After inserting , z : balanced ∴ heightDiff ≤1 height(T0) = h+1 ∵ After inserting , y : balanced height(T3) = h+1 ∵ After inserting , x : unbalanced Rebalancing does not change heights of the subtree → ie. Nor of root. So only fix balance facters of inserted path to z and of y. h+3 - h+2 \ Insert at T1 Left Rotate at y h h+1 h+4 z y x T2 T0 T3 T1 // / 1 2 h-1/h h/h+1 h+1/h+2 Right Rotate atx Long Side 1st unbalanced 1st Diff > 1 balanced H.Diff ≤1
19
Proof : Rebalancing Area’ Height’s unchange (Left Subtree of Right Son of x )
Insert at a long side T1 x = 1st unbalanced node, y = son of x, z = son of y height(T2) = ? When height(T1) = h. = h-1 or h ∵ heightDiff (T1,T2) ≤1 & ≠ h+1 ∵ T2 : short side, T1 : long side = h ∵ After inserting , z : balanced ∴ heightDiff ≤1 height(T3) = h+1 ∵ After inserting , y : balanced height(T0) = h+1 ∵ After inserting , x : unbalanced Rebalancing does not change heights of the subtree → ie. Nor of root. So only fix balance facters of inserted path to z and of y. Insert at T1 Right Rotate at y h T2 h+1 x T0 \\ 2 y T3 - z T1 h+3 \ h+2 Left Rotate at x h-1/h h/h+1 h+1/h+2 Long Side h+4 / 1 1st unbalanced 1st Diff > 1 balanced H.Diff ≤1
20
Single Right Rotation & Single Left Rotation Algorithms
1. Left subtree of left son of x // Single Right Rotation LeftLeftRotate(node *px) node* py = px->left px->left = py->right py->right = px return py z y T1 T0 x T3 T2 or z y x T1 T2 T3 T0 or px py 3. Right subtree of right son of x // Single Left Rotation RightRightRotate(node *px) node* py = px->right px->right= py->left py->left = px return py z y T2 T3 x T0 T1 or z y x T2 T1 T0 T3 or px py
21
Single Right Rotation & Single Left Rotation Algorithms
// Double Rotation : // Case 2 : Left Rotation then Right Rotation RightLeftRotate(node *px) node* py = px->left px->left = RightRightRotate(px->left) py = LeftLeftRotate(px) return py 2. Right subtree of left son of x z y x T2 T0 T3 T1 or 1 2 px py 4. Left subtree of right son of x // Double Rotation : // Case 4 : Right Rotation then Left Rotation LeftRightRotate (node *px) node *py = px->right px->right = LeftLeftRotate(px->right) py = RightRightRotate(px) return py z y x T1 T3 T0 T2 or 1 2 px py
22
B ตัวค่ากลาง เป็น root ใหม่ เสมอ
Single Rotation in AVL x = 1st unbalanced node, y = son of x, z = son of y A < B < C T0<T1<T2<T3 Left subtree of left son of x A B C A B C T1 T0 z y x T2 T3 or h+3 - / h h+1 h+2 z y T1 T0 x T3 T2 h+3 - \ z y T1 T0 x T3 T2 h+1 h h+2 สรุปรูปผลลัพธ์ B ตัวค่ากลาง เป็น root ใหม่ เสมอ Tj Tj Height(Tj) = h ตัวเดียว Tj คือตัวที่คู่กับ Ti ที่ insert node ใหม่เข้าไป นอกนั้น height(T) = h+1 หมด 2. Right subtree of right son of x z y x T2 T1 T0 T3 or A B C A B C h+3 - \ h h+1 h+2 z y T2 T3 x T0 T1 h+3 - \ h h+1 h+2 z y T2 T3 x T0 T1 Tj Tj
23
Double Rotations in AVL
x = 1st unbalanced node, y = son of x, z = son of y A < B < C T0<T1<T2<T3 Right subtree of left son of x z y x T2 T0 T3 T1 1 2 or A B C A B C h+3 - h+2 \ y z T1 T0 x T3 T2 h+1 h h+3 / - h+2 y z T1 T0 x T3 T2 h h+1 สรุปรูปผลลัพธ์ B ตัวค่ากลาง เป็น root ใหม่ เสมอ Tj Tj Height(Tj) = h ตัวเดียว Tj คือตัวที่คู่กับ Ti ที่ insert node ใหม่เข้าไป นอกนั้น height(T) = h+1 หมด 3. Left subtree of right son of x T3 z y x T1 T0 T2 or 1 2 A B C A B C h+3 \ - h+2 y z T2 T3 x T0 T1 h h+1 h+3 - h+2 / y z T2 T3 x T0 T1 h+1 h Tj Tj
24
What is the Result AVL after insert 70 ?
50 30 10 60 - 35 45 40 \ 1 5 3 7 15 25 20 55 65 70
25
Result AVL after Insert 70
50 30 10 60 - 35 45 40 1 5 3 \ 7 15 25 20 55 65 70 \\ \\ 50 30 10 T3 55 65 60 70 \ - T2 35 45 40 1 5 3 7 T1 15 25 20
26
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
27
Which Representations ?
typedef int T; struct node{ T data; struct node *left, *right; }; typedef struct node node; Dynamic 9 3 5 6 1 r Linked Array Sequential (Implicit) Array G A C L M F I D B 13 14 6 2 11 12 5 9 10 4 7 8 3 1 left data right father 1 9 2 3 5 4 6 -1 2 -1 4 1 3 4 root 4 2 -1 2 -1 A B C D F G I L M 1 2 3 4 5 6 7 8 9 10 11 12 13 14
28
Sequential Array (Implicit Array)
G A C L M F I D B 13 14 6 2 11 12 5 9 10 4 7 8 3 1 A B C D F G I L M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ง่าย ต้องกะขนาด array เพิ่มขึ้นอีก 1 level # ที่เพิ่มมากกว่าที่มีอยู่เดิมอยู่ (คิดเต็มที่ full binary tree) ถ้ากะขนาด array ถูก และ tree ใช้พื้นที่ส่วนใหญ่ของ array เช่น almost complete binary tree) จะ save space เพราะไม่ต้องมีฟิลด์ left, right, father
29
Linked Array 1 9 2 3 5 4 6 r -1 2 -1 4 1 3 4 root 4 2 -1 2 -1 6 3 9 1
left data right father 1 9 2 3 5 4 6 9 3 5 6 1 r -1 2 -1 4 1 3 4 root 4 2 -1 2 -1 ต้องใช้ left, right (or father) ฟิลด์ flexible กว่า ดึง node มาใช้จาก pool กลาง available list จำนวน node ถูก limited โดยขนาดของ array ตำแหน่งของ node ไม่เจาะจงเหมือน sequential
30
Dynamic 9 3 5 6 1 r จำนวน node ถูกจำกัดโดย memory
31
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
32
n-ary Trees N-ary Tree : Each node has at most n children. A B C D E F G Ternary Tree.
33
Generic Tree Generic Tree : Each node has unrestricted number of children. root T3 T10 T4 T1 T2 B C D A E F G H I J K L M N P Q
34
Implementation of Generic Tree
B C D E F G typedef int T; struct treeNode{ T data; struct treeNode *firstChild struct treeNode *nextSibling; }; typedef struct treeNode treeNode; H I J K L M N P Q B C D A E F G H I J K L M N P Q firstChild nextSibling nextSibling nextSibling nextSibling nextSibling firstChild firstChild firstChild firstChild firstChild nextSibling nextSibling
35
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
36
Multiway Search Tree Multiway Tree order n : has at most n subtrees (has 0, 1,... or n subtrees) (#max. sons = n) Order 4: มีลูกได้มากที่สุด 4 ตัว Root has maximum sons = 4 How many keys of the father of 4 sons ? Multiway Search Tree : for every key K right decendents > K left decendents ≤ K 3 So, for order 4, #maximum key = 3 For order n : #max. sons = n #max. Keys = n-1 leaf : node ที่ไม่มีลูกเลย Semi-leaf node : มีลูกอย่างน้อย 1 ตัวเป็น NULL Semi-leaf Full node : node ที่มีจำนวน key เต็มที่ Full node Order 4 #max. sons = 4 #max. keys = 3 leaf = NULL
37
Multiway Search Tree Multiway Tree order n : has at most n subtrees (has 0, 1,... or n subtrees) (#max. sons = n) Order 4: มีลูกได้มากที่สุด 4 ตัว Root has maximum sons = 4 How many keys of the father of 4 sons ? Multiway Search Tree : for every key K right decendents > K left decendents ≤ K 3 So, for order 4, #maximum key = 3 For order n : #max. sons = n #max. Keys = n-1 leaf : node ที่ไม่มีลูกเลย Semi-leaf node : มีลูกอย่างน้อย 1 ตัวเป็น NULL Semi-leaf Full node : node ที่มีจำนวน key เต็มที่ Full node Order 4 #max. sons = 4 #max. keys = 3 leaf = NULL
38
Multiway Search Tree
39
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
40
Top Down Tree Top Down Tree : Non full node must be leaf.
Order n : has at most n subtrees (has 0, 1,... or n subtrees) (#max. sons = n) Fill up the existing nodes before creating a new node ! → have fewer nodes as possible → fewer nodes : shorter height ! Order 3 #max. sons = 3 #max. keys = 2 Insert 57 Must be with 55 Not in a new node. 57
41
Unbalanced Tree
42
Balanced Tree Balanced Tree : every leaf node is at the same level (Perfect balance , perfectly height-balanced)
43
Balanced Tree Balanced Tree : every leaf node is at the same level (Perfect balance , perfectly height-balanced)
44
Tree 2 AVL Tree Height Balanced Tree Which Representions ? n-ary Tree
Generic Tree Multiway Search Tree Top Down Tree B-Tree Tree Definitions Binary Tree Traversals Binary Search Tree Representations Application : Expression Tree
45
Balance Trees Balanced Tree : every leaf node is at the same level (Perfect balance , perfectly height-balanced) Order 3 #max. sons = 3 #max. keys = 2
46
Multi-way search tree order n #max son = n, #max keys = n-1
B-Trees B-tree order n Multi-way search tree order n #max son = n, #max keys = n-1 Balanced tree ทุก node ยกเว้น root node มีจำนวน non-empty subtree #min sons = n/2 (Half Full) EX. order 2 : #max sons =2 , #min sons = 2/2 = 1 ∴ Binary ที่เป็น complete binary tree จะเป็น B-tree order 5 : #max sons = 5 , #min sons = 5/2 = 2.5 = 3 order 201 : #max sons = 201 , #min sons = 201/2 = 101
47
order 5 #max son = 5, #max keys = 4
B-Tree Variation order 5 #max son = 5, #max keys = 4 Half Full (ยกเว้น root node) #min sons = 5/2 = 2.5 = 3 B-tree -> variations internal nodes : เก็บเฉพาะ key เพื่อประหยัดพื้นที่, order กำหนดจำนวนลูก external nodes : เก็บ data ทั้ง record, ค่า L กำหนดจำนวน record/node ถ้า L = 5 : #max data = 5, #min data = 5/2 = 2.5 = 3
48
B-Tree (Variation) Insertion
Insert at leaf: until full, if full -> split B-Tree (Variation) Insertion Insertion consider #maximum order 5 : #max son = 5, Internal : #max keys = 4, #min sons = 5/2 = 3 Leaf L = 5: #max data = 5, #min data = 5/2 = 3
49
B-Tree (Variation) Insertion
Insert at leaf: until full, if full -> split B-Tree (Variation) Insertion order 5, #max key = 5-1=4 L=5 #leaf max data = 5 Insertion consider #maximum order 5 : #max son = 5, Internal : #max keys = 4, #min sons = 5/2 = 3 Insertion consider #maximum Leaf L = 5: #max data = 5, #min data = 5/2 = 3
50
B-Tree (Variation) Insertion
Insert at leaf: until full, if full -> split B-Tree (Variation) Insertion order 5, #max key = 5-1=4 L=5 #leaf max data = 5 Insertion consider #maximum order 5 : #max son = 5, Internal : #max keys = 4, #min sons = 5/2 = 3 Leaf L = 5: #max data = 5, #min data = 5/2 = 3
51
B-Tree (Variation) Insertion
Insert at leaf: until full, if full -> split B-Tree (Variation) Insertion order 5, #max key = 5-1=4 L=5 #leaf max data = 5 Insertion consider #maximum order 5 : #max son = 5, Internal : #max keys = 4, #min sons = 5/2 = 3 Leaf L = 5: #max data = 5, #min data = 5/2 = 3
52
B-Tree (Variation) Deletion
Delete at leaf: until low, if low -> borrow B-Tree (Variation) Deletion Deletion consider #minimum Internal order 5 : #min sons = 5/2 = #min keys = 2 Leaf L = 5: #max data = 5, #min data = 5/2 = 3 Borrowing 1. ยืมพี่น้อง(ผ่านพ่อ) เช่น del 49 2. ยืมพ่อ ต้อง consolidate เช่น del 84 พ่อไม่มี พ่อยืม -พี่น้องพ่อ(ผ่านปู่) . . . Delete at leaf: until low, if low -> borrow
53
B-Tree (Variation) Deletion
Delete at leaf: until low, if low -> borrow B-Tree (Variation) Deletion Deletion consider #minimum Internal order 5 : #min sons = 5/2 = #min keys = 2 Leaf L = 5: #max data = 5, #min data = 5/2 = 3 Borrowing 1. ยืมพี่น้อง(ผ่านพ่อ) เช่น del 49 2. ยืมพ่อ ต้อง consolidate เช่น del 84 พ่อไม่มี พ่อยืม -พี่น้องพ่อ(ผ่านปู่) . . .
54
B-Tree (Variation) Deletion
Delete at leaf: until low, if low -> borrow B-Tree (Variation) Deletion Deletion consider #minimum Internal order 5 : #min sons = 5/2 = 3 #min keys = 2 Leaf L = 5: #max data = 5, #min data = 5/2 = 3 Borrowing 1. ยืมพี่น้อง(ผ่านพ่อ) เช่น del 49 2. ยืมพ่อ ต้อง consolidate เช่น del 84 พ่อไม่มี พ่อยืม -พี่น้องพ่อ(ผ่านปู่) . . .
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.