3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees

Slides:



Advertisements
Similar presentations
AVL Trees binary tree for every node x, define its balance factor
Advertisements

Lecture 9 : Balanced Search Trees Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Rotating Nodes How to balance a node that has become unbalanced after the addition of one new node.
AVL Trees Balancing. The AVL Tree An AVL tree is a balanced binary search tree. What does it mean for a tree to be balanced? It means that for every node.
CS261 Data Structures AVL Trees. Goals Pros/Cons of a BST AVL Solution – Height-Balanced Trees.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
AVL Tree Smt Genap Outline AVL Tree ◦ Definition ◦ Properties ◦ Operations Smt Genap
CS 171: Introduction to Computer Science II
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
Tirgul 5 AVL trees.
1 Balanced Search Trees  several varieties  AVL trees  trees  Red-Black trees  B-Trees (used for searching secondary memory)  nodes are added.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
AVL-Trees (Part 1: Single Rotations) Lecture COMP171 Fall 2006.
1 Binary Search Trees Implementing Balancing Operations –AVL Trees –Red/Black Trees Reading:
B-Tree B-Tree is an m-way search tree with the following properties:
Slides by Jagoda Walny CPSC 335, Tutorial 02 Winter 2008
AVL Tree Example (This is the example we did in tutorial on Thursday) Slides by Jagoda Walny CPSC 335, Tutorial 02 Winter 2008.
CSC 2300 Data Structures & Algorithms February 13, 2007 Chapter 4. Trees.
Indexing (cont.). Insertion in a B+ Tree Another B+ Tree
AVL Trees ITCS6114 Algorithms and Data Structures.
Balanced Search Trees CS 3110 Fall Some Search Structures Sorted Arrays –Advantages Search in O(log n) time (binary search) –Disadvantages Need.
Balanced Trees Balanced trees have height O(lg n).
1 B-Trees Section AVL (Adelson-Velskii and Landis) Trees AVL tree is binary search tree with balance condition –To ensure depth of the tree is.
Properties of BST delete We first do the normal BST deletion: – 0 children: just delete it – 1 child: delete it, connect child to parent – 2 children:
1 Joe Meehean.  BST efficiency relies on height lookup, insert, delete: O(height) a balanced tree has the smallest height  We can balance an unbalanced.
Weight balance trees (Nievergelt & Reingold 73)
Binary Search Trees A binary tree:A binary tree: –No node has more than two child nodes (called child subtrees). –Child subtrees must be differentiated,
Analysis of Red-Black Tree Because of the rules of the Red-Black tree, its height is at most 2log(N + 1). Meaning that it is a balanced tree Time Analysis:
Announcements Exam Friday. More Physical Storage Lecture 10.
Data Structures and Algorithms TREE-TRAVERSAL. Searching - Re-visited Binary tree O(log n) if it stays balanced Simple binary tree good for static collections.
AVL Tree Definition: Theorem (Adel'son-Vel'skii and Landis 1962):
Copyright Curt Hill Balance in Binary Trees Impact on Performance.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
CompSci 100E 41.1 Balanced Binary Search Trees  Pathological BST  Insert nodes from ordered list  Search: O(___) ?  The Balanced Tree  Binary Tree.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 20 AVL Trees.
1 CSC TREES AVL & BALANCED TREES. 2 Balanced Trees The advantage of balanced trees is that we can perform most operation in time proportional to.
CSE 3358 NOTE SET 13 Data Structures and Algorithms.
AVL Trees 1. Balancing a BST Goal – Keep the height small – For any node, left and right sub-tree have approximately the same height Ensures fast (O(lgn))
AVL TREES By Asami Enomoto CS 146 AVL Tree is… named after Adelson-Velskii and Landis the first dynamically balanced trees to be propose Binary search.
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
AVL Tree: Balanced Binary Search Tree 9.
G64ADS Advanced Data Structures
Binary search tree. Removing a node
Red Black Trees
CS202 - Fundamental Structures of Computer Science II
Chapter 11: Multiway Search Trees
CS202 - Fundamental Structures of Computer Science II
Balanced Binary Search Trees
AVL DEFINITION An AVL tree is a binary search tree in which the balance factor of every node, which is defined as the difference between the heights of.
Introduction Applications Balance Factor Rotations Deletion Example
Chapter 26 AVL Trees Jung Soo (Sue) Lim Cal State LA.
AVL Trees A BST in which, for any node, the number of levels in its two subtrees differ by at most 1 The height of an empty tree is -1. If this relationship.
Chapter 29 AVL Trees.
Tree.
AVL Tree 27th Mar 2007.
Design and Analysis of Algorithms
Lecture 26 Multiway Search Trees Chapter 11 of textbook
CS202 - Fundamental Structures of Computer Science II
2-3-4 Trees Red-Black Trees
AVL Search Tree put(9)
Lecture No.20 Data Structures Dr. Sohail Aslam
CS202 - Fundamental Structures of Computer Science II
AVL-Trees (Part 1).
ITCS6114 Algorithms and Data Structures
Goals Design decisions Design Insertion
CO4301 – Advanced Games Development Week 5 Walkthrough of Red-Black Tree Insertion Gareth Bellaby.
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
Presentation transcript:

3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees Chen Song

Height-Balanced Trees

Height-Balanced Trees Height – The maximum length of any path from the root to a leaf. Height-Balanced Tree – In each interior node, the height of the right subtree and left subtree differ by at most one.

Height-Balanced Trees Example:

Height-Balanced Trees Theorem A height-balanced tree of height h has at least ( 3+ 5 2 5 ) ( 1+ 5 2 ) ℎ − ( 3− 5 2 5 ) ( 1− 5 2 ) ℎ leaves.

Height-Balanced Trees Tree T Tree T has at least leaves: leaves(h)=leaves(h-1)+leaves(h-2) leaves(0)=1 leaves(1)=2 Characteristic equation: xh=xh-1+xh-2 => x2-x-1=0

Height-Balanced Trees Insert and Delete After insert or delete: Case 1: Tree is still balanced Case 2: Tree is not balanced at node n |n->left-height − n->right-height|=2

Height-Balanced Trees 1. n->left->height = n->right->height+2 and n->left->left->height=n->right->height+1 Right rotation on node n 2. n->left->height = n->right->height+2 and n->left->left->height=n->right-height Left rotation on node n->left, and follow right rotation on node n

Height-Balanced Trees 3. n-> right->height = n->left->height+2 and n->right->right->height=n->left->height+1 Left rotation on node n->left 4. n->right->height = n->left->height+2 and n->right->right->height=n->left-height Right rotation on node n->right, and follow left rotation on node n

Height-Balanced Trees Height-Balanced Tree structure supports search, insert, and delete in O(logn) time Search => O(logn) Insert => search + insert + rebalance => O(logn) O(logn) O(1) O(logn) Delete => search + delete + rebalance => O(logn) O(logn) O(1) O(logn)

Weight-Balanced Trees

Weight-Balanced Trees Weight – The number of leaves of a tree. Weight-Balanced Tree – The weight of the right and left subtree in each node differ by at most one.

Weight-Balanced Trees For each subtree, the left and right sub-subtrees has each at least a fraction of α of total weight of the subtree. αWT≤WT1≤(1-α)WT αWT≤WT2≤(1-α)WT Tree T: T1 T2

Weight-Balanced Trees Theorem An α-weight-balanced tree of height h≥2 has at least ( 1 1−α ) ℎ leaves.

Weight-Balanced Trees Rebalance n is current node α∈[ 2 7 , 1− 1 2 ] Case 1: n->left->weight ≥ α*n->weight and n->right->weight ≥ α*n->weight No rebalancing

Weight-Balanced Trees Case 2: n->right->weight ≥ α*n->weight If n->left->left->weight > (α+ε)n->weight, do right rotation on node n Else left rotation on n->left, followed right rotation on node n. ε ≤ α2-2α+ 1 2

Weight-Balanced Trees Case 3: n->left->weight ≥ α*n->weight If n->right->right->weight > (α+ε)n->weight, do left rotation on node n Else right rotation on n->right, followed left rotation on node n.

Weight-Balanced Trees Theorem The weight-balanced tree structure supports search, insert, and delete in O(logn) time. Search => O(logn) Insert => search + insert + rebalance => O(logn) O(logn) O(1) O(logn) Delete => search + delete + rebalance => O(logn) O(logn) O(1) O(logn)

END