AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.

Slides:



Advertisements
Similar presentations
1 AVL Trees (10.2) CSE 2011 Winter April 2015.
Advertisements

Trees Types and Operations
Balanced Binary Search Trees
Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees.
A balanced life is a prefect life.
1 Balanced Search Trees  several varieties  AVL trees  trees  Red-Black trees  B-Trees (used for searching secondary memory)  nodes are added.
1 /26 Red-black tree properties Every node in a red-black tree is either black or red Every null leaf is black No path from a leaf to a root can have two.
1 /26 Red-black tree properties Every node in a red-black tree is either black or red Every null leaf is black No path from a leaf to a root can have two.
1 Binary Search Trees Implementing Balancing Operations –AVL Trees –Red/Black Trees Reading:
Trees and Red-Black Trees Gordon College Prof. Brinton.
Self-Balancing Search Trees Chapter 11. Chapter 11: Self-Balancing Search Trees2 Chapter Objectives To understand the impact that balance has on the performance.
Fall 2007CS 2251 Self-Balancing Search Trees Chapter 9.
Self-Balancing Search Trees Chapter 11. Chapter Objectives  To understand the impact that balance has on the performance of binary search trees  To.
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
Deletion algorithm – Phase 2: Remove node or replace its with successor TreeNode deleteNode(TreeNode n) { // Returns a reference to a node which replaced.
Binary Search Trees Chapter 7 Objectives
By : Budi Arifitama Pertemuan ke Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
Balanced Search Trees Chapter 27 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Balanced Trees AVL Trees Red-Black Trees 2-3 Trees Trees.
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:
© 2004 Goodrich, Tamassia Red-Black Trees v z.
Red Black Tree Smt Genap Outline Red-Black Trees ◦ Motivation ◦ Definition ◦ Operation Smt Genap
1. 2 Setting Up Deletion As with binary search trees, we can always delete a node that has at least one external child If the key to be deleted is stored.
CSIT 402 Data Structures II
Beyond (2,4) Trees What do we know about (2,4)Trees? Balanced
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 8.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
1 Balanced Trees There are several ways to define balance Examples: –Force the subtrees of each node to have almost equal heights –Place upper and lower.
Advanced Data Structures and Implementation Top-Down Splay Trees Top-Down Splay Trees Red-Black Trees Red-Black Trees Top-Down Red Black Trees Top-Down.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Starting at Binary Trees
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
Chapter 13 A Advanced Implementations of Tables. © 2004 Pearson Addison-Wesley. All rights reserved 13 A-2 Balanced Search Trees The efficiency of the.
M-ary Trees. m-ary trees Some trees need to be searched efficiently, but have more than two children l parse trees l game trees l genealogical trees,
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Balanced Search Trees Chapter 19 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
1 Binary Search Trees  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
Red-Black Trees an alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A.
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.
Binary Search Trees Chapter 7 Objectives
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
Lecture 23 Red Black Tree Chapter 10 of textbook
AA Trees.
G64ADS Advanced Data Structures
Red-Black Trees v z Red-Black Trees Red-Black Trees
Search Trees.
Red Black Trees
CS202 - Fundamental Structures of Computer Science II
CS202 - Fundamental Structures of Computer Science II
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees Bottom-Up Deletion.
Binary Search Tree In order Pre order Post order Search Insertion
Wednesday, April 18, 2018 Announcements… For Today…
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees v z /20/2018 7:59 AM Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
CS202 - Fundamental Structures of Computer Science II
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
Red-Black Trees Bottom-Up Deletion.
Binary Search Trees Chapter 7 Objectives
CS202 - Fundamental Structures of Computer Science II
Red Black Trees (Guibas Sedgewick 78)
Red-black tree properties
CS202 - Fundamental Structures of Computer Science II
Red-Black Trees v z /6/ :10 PM Red-Black Trees
CS202 - Fundamental Structures of Computer Science II
Presentation transcript:

AA Trees another alternative to AVL trees

Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced tree supports efficient operations, since most operations only have to traverse one or two root-to-leaf paths. There are many implementations of balanced BSTs, including AVL trees, Red- Black trees and AA trees.

Properties of AA Trees An AA tree satisfies the properties of Red- Black trees plus one more: 1Every node is colored either red or black 2The root is black 3If a node is red, both of its children are black. 4Every path from a node to a null reference has the same number of black nodes 5 Left children may NOT be red

Advantage of AA Trees AA trees simplify the algorithms –It eliminates half the restructuring cases –It simplifies deletion by removing an annoying case if an internal node has only one child, that child must be a red right child We can always replace a node with the smallest child in the right subtree [it will either be a leaf or have a red child]

Representing the Balance information In each node we store a level. The level is defined by these rules –If a node is a leaf, its level is 1 –If a node is red, its level is the level of its parent –If a node is black, its level is one less than the level of its parent The level is the number of left links to a null reference.

Links in an AA tree A horizontal link is a connection between a node and a child with equal levels –Horizontal links are right references –There cannot be two consecutive horizontal links –Nodes at level 2 or higher must have two children –If a node has no right horizontal link, its two children are at the same level

Example of an AA Tree

Insertion A new item is always inserted at the bottom level In the previous example, inserting 2 will create a horizontal left link In the previous example, inserting 45 generates consecutive right links After inserting at the bottom level, we may need to perform rotations to restore the horizontal link properties

skew - remove left horizontal links PX A BC PX A BC

split - remove consecutive horizontal links XP A B G X P A B G

skew/split A skew removes a left horizontal link A skew might create consecutive right horizontal links We should first process a skew and then a split, if necessary After a split, the middle node increases a level, which may create a problem for the original parent