Different binary search trees can represent the same set of values (Fig.2). Vladimir Shelomovskii, Unitech, Papua New Guinea. Binary search tree.

Size: px
Start display at page:

Download "Different binary search trees can represent the same set of values (Fig.2). Vladimir Shelomovskii, Unitech, Papua New Guinea. Binary search tree."

Transcription

1 1 Vladimir Shelomovskii, Unitech, Papua New Guinea, CS411 Binary search tree We can represent a binary search tree by a linked data structure in which each node is an object. Each node contains (Fig.1): key (an integer value for searching the object), satellite data (any data need for using, connected with the key) left a pointer to the left child, right a pointer to the right child, p a pointer to the parent. If the child or the parent is missing, the appropriate attribute contains the value NIL. The root node is the only node in the tree whose parent is NIL. NIL's shown by yellow in Fig.1. The keys in a binary search tree are always stored in such a way as to satisfy the binary-search-tree property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then x.key y.key. If y is a node in the right subtree of x, then x.key y.key. For any node x, the keys in the left subtree of x are at most x.key, and the keys in the right subtree of x are at least x.key. Fig.1. Each node has attributes: key, p, left, and right. The sketch (in the upper right corner) has not NIL details. In the next figures the pairs of the arrows changed to segments. The key of the root object is 6, the keys 2, 5, and 5 are in its left subtree, they are no larger than 6, and the keys 7 and 8 in its right subtree are no smaller than 6. The same property holds for every node in the tree. The key 5 in the root s left child is no smaller than the key 2 in the node s left subtree and no larger than the key 5 in the right subtree. Different binary search trees can represent the same set of values (Fig.2).

2 2 Fig.2. The tree has the same set of values, the same nodes as tree in Fig. 1, but the connection of the nodes is different Keys printing The binary-search-tree property allows us to print out all keys in a binary search tree (or all keys in x-subtree) in sorted order by a recursive algorithm, called an inorder tree walk. This algorithm prints the key of the root of a subtree between printing the values in its left subtree and printing those in its right subtree. It uses the pointer to the element x for working. To print all the elements in a binary search tree T, we call INORDER-TREE-WALK(T.root) = ITW(T.root). ITW(x) 1 if x NIL then 2 ITW(x.left) 3 print x.key 4 ITW(x.right) end if We use colors and show the in-order tree walk in the case, shown of figure: ITW(pointer to 6) 6 NIL ITW(5 = 6.left) 5 NIL ITW(2 = 5.left) 2 NIL ITW(NIL = 2.left) print(2) ITW(NIL = 2.right) print(5) ITW(5 = 5.right) 5 NIL ITW(NIL = 5.left) print(5) ITW(6 = 5.right) 6 NIL ITW(NIL= 6.left) print(6) ITW(NIL=6.right) print(6) ITW(7 = 6.right) 7 NIL ITW(6 = 7.left) 6 NIL ITW(NIL = 6.left) print(6) ITW(NIL = 6.right)

3 3 print(7) ITW(8 = 7.right) 8 NIL ITW(NIL = 8.left) print(8) ITW(NIL = 8.right) Hence the procedure prints keys in the following order: 2, 5 (green), 5 (indigo), 6 (broun), 6 (root), 6 (pink), 7, 8.

4 4 Searching in a binary search tree We use the following procedure to search for a node with a given key k in a binary search tree. Given a pointer x to the root of the tree and a key k, TREE-SEARCH returns a pointer to a node with the key k if one exists; otherwise, it returns NIL. TREE-SEARCH(x, k) 1 if x = NIL or k = x.key (We do this if we get at most one YES) 2 return x 3 if k < x.key (We do this if we get NO and NO in line 1) 4 TREE-SEARCH(x.left, k) 5 else TREE-SEARCH(x.right, k) The procedure begins its search at the root and traces a simple path downward in the tree. For each node x it encounters, it compares the key k with x.key. If two keys are equal, the search terminates. If k is smaller than x.key, the search continues in the left subtree of x. Symmetrically, if k is larger than x.key, the search continues in the right subtree. We use the notation TREE-SEARCH = TS. To search for the object with the key = 13 in the tree with the root 15, use TS(pointer to 15, 13) and follow the path: x = NIL or k = x.key (NO or NO) k < x.key 13 < 15 TS(15.left = pointer to 6, 13) k > x.key 13 > 6 TS(6.right = pointer to 7, 13) k > x.key 13 > 7 TS(7.right = pointer to 13, 13) x = NIL or k = x.key (NO or YES) 13 = 13 return 7.right = pointer to 13. We get the pointer to 13. To search for the object with the key = 14 in the tree with the root 15, use TS (pointer to 15, 14) and follow the path: x = NIL or k = x.key (NO or NO) k < x.key 14 < 15 TS(15.left = pointer to 6, 14) k > x.key 14 > 6 TS(6.right = pointer to 7, 14) k > x.key 14 > 7 TS(7.right = pointer to 13, 14) k < x.key 14 >13 TS(13.right = NIL, 14) x = NIL or k = x.key (YES or NO) return 13.right = NIL. We can rewrite this procedure in an iterative fashion by unrolling the recursion into a while loop. On most computers, the iterative version is more efficient. ITERATIVE-TREE-SEARCH(x, k) 1 while x NIL and k x.key (We do this if we get YES and YES) 2 if k < x.key 3 then x = x.left 4 else x = x.right

5 5 5 return x (We do this if we get at most one NO)

6 6 Minimum and maximum We can always find an element in a binary search tree whose key is a minimum by following left child pointers from the root until we encounter a NIL. The following procedure returns a pointer to the minimum element in the subtree rooted at a given node x, which we assume to be non-nil: TREE-MINIMUM(x) 1 while x.left NIL 2 x = x.left (We do this if we get YES in line 1) 3 return x (We do this if we get NO in line 1) The pseudo-code for TREE-MAXIMUM is symmetric: TREE-MAXIMUM(x) 1 while x.right NIL 2 x = x.right 3 return x To search for the object with the minimum key in the tree with the root 6, use TREE-MINIMUM (pointer to 6) and follow the path: TREE-MINIMUM (pointer to root 6) 6.left NIL YES x = pointer to 5 5.left NIL YES x = pointer to 2 2.left NIL NO return x = pointer to 2

7 7 Successor and predecessor Given a node in a binary search tree, we need to find its successor in the sorted order determined by an inorder tree walk. If all keys are distinct, the successor of a node x is the node with the smallest key greater than x.key. The structure of a binary search tree allows us to determine the successor of a node without ever comparing keys. The following procedure returns the successor of a node x in a binary search tree if it exists, and NIL if x has the largest key in the tree: TREE-SUCCESSOR(x) 1 if x.right NIL 2 return TREE-MINIMUM(x.right) (We do this if we get YES in line 1) 3 y = x.p 4 while y NIL and x = y.right 5 x = y (We do this if we get YES and YES in line 4) 6 y = y.p 7 return y (We do this if we get at most one NO in line 4) We break the code for TREE-SUCCESSOR into two cases. Case 1. The right subtree of the node x is nonempty, x.right NIL. The successor of x is just the leftmost node in x s right subtree, which we find in line 2 by calling TREE-MINIMUM(x.right). We can find the successor of the node with the key 7 using TREE-SUCCESSOR(7) TREE-SUCCESSOR(7) 1 if x.right NIL YES (7.right = 13) 2 return TREE-MINIMUM(7) = pointer to 9. Case 2. The right subtree of the node x is empty, x.right = NIL. If x has a successor y, then y is the lowest ancestor of x whose left child is also an ancestor of x. We can find the successor of the node with the key 13: To find y, we simply go up the tree from x until we encounter a node that is the left child of its parent; lines 3 7 of TREE-SUCCESSOR handle this case. TREE-SUCCESSOR(13) 1 if x.right NIL NO (13.right = NIL) 3 y = x.p y = 13.p = pointer to 7 4 while y NIL and x = y.right (YES and YES: 13 = 7.right) 5 x = y x = 7 6 y = y.p y = 7.p = pointer to 6 4 y NIL and x = y.right (YES and YES: 7 = 6.right) 5 x = y x = 6 6 y = y.p y = 6.p = pointer to 15 4 y NIL and x = y.right (YES and NO: 6 = 15.right) 7 return y = pointer to 15

8 8 The procedure TREE-PREDECESSOR is symmetric to TREE-SUCCESSOR. Even if keys are not distinct, we define the successor and predecessor of any node x as the node returned by calls TREE-SUCCESSOR(x) and TREE-PREDECESSOR(x), respectively.

9 9 Insertion The operations of insertion and deletion cause the dynamic set represented by a binary search tree to change. The data structure must be modified to reflect this change, but in such a way that the binary-search-tree property continues to hold. To insert a new value into a binary search tree, we use the procedure TREE-INSERT. The procedure takes a node z for which z.key = z 0, z.left = NIL, and z.right = NIL. It modifies T and some of the attributes of z in such a way that it inserts z into an appropriate position in the tree. TREE-INSERT(T, z) 1 y = NIL 2 x = T.root 3 while x NIL 4 y = x 5 if z.key < x.key 6 x = x.left 7 else x = x.right 8 z.p = y 9 if y = NIL 10 T.root = z // tree T was empty 11 else if z.key < y.key 12 y.left = z 13 else y.right = z Figure shows how TREE-INSERT works. Just like the procedure TREE-SEARCH it begins at the root of the tree and the pointer x traces a simple path downward looking for a NIL to replace with the input item z. The procedure maintains the trailing pointer y as the parent of x. After initialization, the while loop in lines 3 7 causes these two pointers to move down the tree, going left or right depending on the comparison of z.key with x.key, until x becomes NIL. This NIL occupies the position where we wish to place the input item z. We need the trailing pointer y, because by the time we find the NIL, the search has proceeded one step beyond the node that needs to be changed. Lines 8 13 set the pointers that cause z to be inserted. Let z be: z = (z.key = 13, z.left = NIL, z.right = NIL, z.p) TREE-INSERT(T, z): 1 y = NIL, 2 x = T.root = pointer to 12 Step 1, x = pointer to 12 3 while x NIL YES 4 y = pointer to 12, 5 z.key =13 > x.key = 12 7 x = x.right = pointer to 18 8 z.p = y = pointer to z.key =13 > y.key = y.right = pointer to 13

10 10 Step 2, x = pointer to 18 3 while x NIL, YES: x = pointer to 18 4 y = x = pointer to 18 5 z.key =13 < x.key = 18 6 x = x.left = pointer to 15 8 z.p = y = pointer to z.key =13 < y.key = y.left = pointer to 13 Step 3, x = pointer to 15 3 while x NIL, YES: x = pointer to 15 4 y = x = pointer to 15 5 z.key =13 < x.key = 15 6 x = x.left = 15.left = NIL 8 z.p = y = pointer to z.key =13 < y.key = y.left = 15.left = pointer to 13 Finish 3 while x = NIL NO: x = NIL Exit The result: z = (z.key = 13, z.left = NIL, z.right = NIL, z.p = pointer to 15) y = (y.key = 15, y.left = pointer to 13, y.right = pointer to 17, y.p = pointer to 18) We need to change the object in table with the key = 15 by the object y.

11 11 Transplantation A subroutine TRANSPLANT replaces one subtree as a child of its parent with another subtree. TRANSPLANT replaces the subtree rooted at the node u with the subtree rooted at the node v: the node u s parent becomes the node v s parent, the node u s parent ends up having v as its appropriate child. If v = NIL, the procedure deletes the subtree rooted at the node u. TRANSPLANT(T, u, v) 1 if u.p = NIL 2 T.root = v else 3 if u = u.p.left 4 u.p.left = v 5 else u.p.right = v 6 if v NIL 7 v.p = u.p Case 1: u is the root of T: u.p = NIL. Lines 1 2 handle this case by changing T.root = v. Line 7 updates v.p = u.p if v is non-nil. Case 2: u is a left child of its parent,v is non-nil: 3 u = u.p.left 4 Line 4 takes care of updating u.p.left = v. 7 Line 7 updates v.p = u.p. Case 3: u is a right child of its parent, v is non-nil: 3 u u.p.left, hence u = u.p.right. 5 Line 5 updates u.p.right = v. 7 Line 7 updates v.p = u.p. Case 3, before TRANSPLANT Case 3, after TRANSPLANT Case 4: v = NIL. If u is a right child of its parent, line 5 updates u.p.right = NIL. If u is a left child of its parent, line 4 updates u.p.left = NIL.

12 Case 4, before TRANSPLANT Case 4, after TRANSPLANT Note that TRANSPLANT does not update v.left and v.right. 12

13 13 Deletion The procedure for deleting a given node z from a binary search tree T takes as arguments pointers to T and z. The procedure is: TREE-DELETE(T, z) if 1 z.left = NIL 2 TRANSPLANT(T, z, z.right) else if 3 z.right = NIL 4 TRANSPLANT(T, z, z.left) else 5 y = TREE-MINIMUM(z.right) 6 if y.p z 7 TRANSPLANT(T, y, y.right) 8 y.right = z.right 9 y.right.p = y 10 TRANSPLANT(T, z, y) 11 y.left = z.left 12 y.left.p = y The overall strategy for deleting a node z from a binary search tree T has four basic cases. Case 1: z has no children. z.left = NIL and z.right = NIL. We remove it by modifying its parent to replace z with NIL as its child. TREE-DELETE(T, z) call 2 TRANSPLANT(T, z, z.right = NIL). The procedure deletes the subtree rooted at the node z, hence deletes z. Case 1, before DELETE Case 1, after DELETE Case 2: z has just one child. z.left = NIL or z.right = NIL. We elevate that child to take z s position in the tree by modifying z s parent to replace z by z s child. Case 2a 1 If z.left = NIL 2 TRANSPLANT(T, z, z.right). Case 2b 3 If z.right = NIL 4 TRANSPLANT(T, z, z.left).

14 14 Case 2b, before DELETE Case 2b, after DELETE Case 3,4: z has two children. We find z s successor y. Successor y is in z s right subtree. Case 3: z has two children. Successor y is z s right child. TREE-DELETE(T, 18) successor y = 19 y.right = TRANSPLANT(T, z, y) 11 y.left = z.left 12 y.left.p = y Case 3, before DELETE Case 3, after TRANSPLANT Case 3, after DELETE Case 4: z has two children. Successor y is not z s right child. We splice y out of its current location and have it replace z in the tree. The rest of z s original right subtree becomes y s new right subtree, and z s left subtree becomes y s new left subtree. TREE-DELETE(T, 12) successor y = 13 y.right = 14 7 TRANSPLANT(T, y, y.right) 10 TRANSPLANT(T, z, y) 8 y.right = z.right 11 y.left = z.left 9 y.right.p = y 12 y.left.p = y Case 4, before DELETE Case 4, after 7, 8, 9 Case 4, after DELETE

15 15 Red-black trees A red-black tree is a binary search tree with one extra bit of storage per node: its color, which can be either RED or BLACK. By constraining the node colors on any simple path from the root to a leaf, red-black trees ensure that no such path is more than twice as long as any other, so that the tree is approximately balanced. Each node of the tree now contains the attributes color, key, left, right, and p. If a child or the parent of a node does not exist, the corresponding pointer attribute of the node contains the value NIL. We shall regard these NILs as being pointers to leaves (external nodes) of the binary search tree and the normal, key-bearing nodes as being internal nodes of the tree. A red-black tree is a binary tree that satisfies the following red-black properties: 1. Every node is either red or black. 2. The root is black. 3. Every leaf (NIL) is black. 4. If a node is red, then both its children are black. 5. For each node, all simple paths from the node to descendant leaves contain the same number of black nodes. The Lecture Hash tables is the part of the undergraduate course CS411 Introduction to Algorithms by Ass. Prof. V. Shelomovskii for University of Technology, Lae, Papua New Guinea. The base of the Lecture course is: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. Introduction to Algorithms. Third Edition. The MIT Press, Cambridge, Massachusetts London, England, 2009.

Algorithms, Spring 2014, CSE, OSU Lecture 4: Binary search trees

Algorithms, Spring 2014, CSE, OSU Lecture 4: Binary search trees 6331 - Algorithms, Spring 2014, CSE, OSU Lecture 4: Binary search trees Instructor: Anastasios Sidiropoulos January 15, 2014 Binary search trees For every node x: x.k : key x.p : pointer to the parent

More information

Binary search trees (BST) Binary search trees (BST)

Binary search trees (BST) Binary search trees (BST) Tree A tree is a structure that represents a parent-child relation on a set of object. An element of a tree is called a node or vertex. The root of a tree is the unique node that does not have a parent

More information

Binary Search Tree. Sorting and Searching in a Dynamic Set. S.V. N. (vishy) Vishwanathan. University of California, Santa Cruz

Binary Search Tree. Sorting and Searching in a Dynamic Set. S.V. N. (vishy) Vishwanathan. University of California, Santa Cruz Binary Search Tree Sorting and Searching in a Dynamic Set S.V. N. (vishy) Vishwanathan University of California, Santa Cruz vishy@ucsc.edu February 29, 2016 S.V. N. Vishwanathan (UCSC) CMPS101 1 / 23 Outline

More information

Binary Search Trees. July 13th, Computer Information Systems. c 2009 Vaidė Narváez

Binary Search Trees. July 13th, Computer Information Systems. c 2009 Vaidė Narváez Binary Search Trees Vaidė Narváez Computer Information Systems July 13th, 2010 Introduction Dynamic set operations: Search, Minimum, Maximum Predecessor, Successor Insert, Delete Time proportional to the

More information

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 3. Graphs CLRS Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 3 Graphs CLRS 12-13 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 57 CLRS 12 Binary Search Trees Binary Search Trees The search tree data structure supports

More information

ץע A. B C D E F G H E, B ( -.) - F I J K ) ( A :. : ע.)..., H, G E (. י : י.)... C,A,, F B ( 2

ץע A. B C D E F G H E, B ( -.) - F I J K ) ( A :. : ע.)..., H, G E (. י : י.)... C,A,, F B ( 2 נת ני ני, 1 עץ E A B C D F G H I J K. E B, ( -.)F- )A( : ע :..)...H,G,E (. י י:.)...C,A,F,B ( 2 עץ E A B C D F G H I J K v : -,w w.v- w-.v :v ע. v- B- 3 ע E A B C D F G H I J K ע - v,1 B ( v-.)? A 4 E

More information

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331 CSE2331/5331 Topic 6: Binary Search Tree Data structure Operations Set Operations Maximum Extract-Max Insert Increase-key We can use priority queue (implemented by heap) Search Delete Successor Predecessor

More information

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 380 ALGORITHM DESIGN AND ANALYSIS CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 12: Red-Black Trees Text Reference: Chapters 12, 13 Binary Search Trees (BST): Review Each node in tree T is a object x Contains attributes: Data Pointers to

More information

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets.

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets. COMP3600/6466 Algorithms 2018 Lecture 12 1 Binary search trees Reading: Cormen et al, Sections 12.1 to 12.3 Binary search trees are data structures based on binary trees that support operations on dynamic

More information

Algorithms, Spring 2014, CSE, OSU Lecture 5: Red-black trees

Algorithms, Spring 2014, CSE, OSU Lecture 5: Red-black trees 6331 - Algorithms, Spring 2014, CSE, OSU Lecture 5: Red-black trees Instructor: Anastasios Sidiropoulos January 17, 2014 Red-black trees For every node x: x.color : red or black x.k : key x.p : pointer

More information

Binary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 21, Antonio Carzaniga 1

Binary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 21, Antonio Carzaniga 1 Binary Search Trees Antonio Carzaniga Faculty of Informatics University of Lugano October 21, 2010 2006 Antonio Carzaniga 1 Binary search trees Outline Randomized binary search trees 2006 Antonio Carzaniga

More information

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion.

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion. Week 8 Binarys 1 2 3 4 5 6 7 General remarks We consider, another important data structure. We learn how to use them, by making efficient queries. And we learn how to build them. Reading from CLRS for

More information

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion.

Week 8. BinaryTrees. 1 Binary trees. 2 The notion of binary search tree. 3 Tree traversal. 4 Queries in binary search trees. 5 Insertion. Week 8 Binarys 1 2 of 3 4 of 5 6 7 General remarks We consider, another important data structure. We learn how to use them, by making efficient queries. And we learn how to build them. Reading from CLRS

More information

Announcements. Problem Set 2 is out today! Due Tuesday (Oct 13) More challenging so start early!

Announcements. Problem Set 2 is out today! Due Tuesday (Oct 13) More challenging so start early! CSC263 Week 3 Announcements Problem Set 2 is out today! Due Tuesday (Oct 13) More challenging so start early! NOT This week ADT: Dictionary Data structure: Binary search tree (BST) Balanced BST - AVL tree

More information

Binary search trees 3. Binary search trees. Binary search trees 2. Reading: Cormen et al, Sections 12.1 to 12.3

Binary search trees 3. Binary search trees. Binary search trees 2. Reading: Cormen et al, Sections 12.1 to 12.3 Binary search trees Reading: Cormen et al, Sections 12.1 to 12.3 Binary search trees 3 Binary search trees are data structures based on binary trees that support operations on dynamic sets. Each element

More information

Binary Search Trees. What is a Binary Search Tree?

Binary Search Trees. What is a Binary Search Tree? Binary Search Trees What is a Binary Search Tree? A binary tree where each node is an object Each node has a key value, left child, and right child (might be empty) Each node satisfies the binary search

More information

The Tail has the pointer value z.next = NIL. the pointer to the next object x.next, down arrows.

The Tail has the pointer value z.next = NIL. the pointer to the next object x.next, down arrows. 1 Vladimir Shelomovskii, Unitech, Papua New Guinea, CS411 Linked list A linked list is a data structure in which the objects are arranged in a linear order. The order in a linked list is determined by

More information

ICS 311, Fall 2017, Problem Set 04, Topics 7 & 8

ICS 311, Fall 2017, Problem Set 04, Topics 7 & 8 ICS 311, Fall 2017, Problem Set 04, Topics 7 & 8 Due by midnight Tuesday 2/16. 35 points. #1. Peer Credit Assignment 1 Point Extra Credit for replying Please list the names of the other members of your

More information

Binary Trees. Recursive definition. Is this a binary tree?

Binary Trees. Recursive definition. Is this a binary tree? Binary Search Trees Binary Trees Recursive definition 1. An empty tree is a binary tree 2. A node with two child subtrees is a binary tree 3. Only what you get from 1 by a finite number of applications

More information

Algorithms. 演算法 Data Structures (focus on Trees)

Algorithms. 演算法 Data Structures (focus on Trees) 演算法 Data Structures (focus on Trees) Professor Chien-Mo James Li 李建模 Graduate Institute of Electronics Engineering National Taiwan University 1 Dynamic Set Dynamic set is a set of elements that can grow

More information

Binary search trees. Support many dynamic-set operations, e.g. Search. Minimum. Maximum. Insert. Delete ...

Binary search trees. Support many dynamic-set operations, e.g. Search. Minimum. Maximum. Insert. Delete ... Binary search trees Support many dynamic-set operations, e.g. Search Minimum Maximum Insert Delete... Can be used as dictionary, priority queue... you name it Running time depends on height of tree: 1

More information

We assume uniform hashing (UH):

We assume uniform hashing (UH): We assume uniform hashing (UH): the probe sequence of each key is equally likely to be any of the! permutations of 0,1,, 1 UH generalizes the notion of SUH that produces not just a single number, but a

More information

Binary Search Trees. 1. Inorder tree walk visit the left subtree, the root, and right subtree.

Binary Search Trees. 1. Inorder tree walk visit the left subtree, the root, and right subtree. Binary Search Trees Search trees are data structures that support many dynamic set operations including Search, Minimum, Maximum, Predecessor, Successor, Insert, and Delete. Thus, a search tree can be

More information

Binary search trees :

Binary search trees : Binary search trees Binary search trees : Search trees are data structures that generally offer the following dynamic-set operations : SEARCH MINIMUM MAXIMUM PREDECESSOR SUCCESSOR INSERT DELETE Basic operations

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,

More information

Binary Search Trees. Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees.

Binary Search Trees. Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees. Binary Search Trees Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees Philip Bille Binary Search Trees Nearest Neighbor Binary Search Trees Insertion

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black

More information

Binary Search Trees. Binary Search Trees. Nearest Neighbor. Nearest Neighbor

Binary Search Trees. Binary Search Trees. Nearest Neighbor. Nearest Neighbor Philip Bille Nearest Neighbor Nearest neighbor. Maintain dynamic set S supporting the following operations. Each element has key x.key and satellite data x.data. PREDECESSOR(k): return element with largest

More information

Chapter 13. Michelle Bodnar, Andrew Lohr. April 12, 2016

Chapter 13. Michelle Bodnar, Andrew Lohr. April 12, 2016 Chapter 13 Michelle Bodnar, Andrew Lohr April 1, 016 Exercise 13.1-1 8 4 1 6 10 14 1 3 5 7 9 11 13 15 We shorten IL to so that it can be more easily displayed in the document. The following has black height.

More information

12 Binary Search Tree

12 Binary Search Tree 12 Binary Search Tree Binary Search Trees (BSTs) are data structures that support many dynamic set operations. The typical operations include: SEARCH INSERT DELETE MINIMUM MAXIMUM PREDECESSOR SUCCESSOR

More information

ECE250: Algorithms and Data Structures Binary Search Trees (Part A)

ECE250: Algorithms and Data Structures Binary Search Trees (Part A) ECE250: Algorithms and Data Structures Binary Search Trees (Part A) Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University

More information

Red-Black Trees. 1 Properties of red-black trees

Red-Black Trees. 1 Properties of red-black trees Red-Black Trees Chapter 12 showed that a binary search tree of height h can support any of the basic dynamic-set operations such as SEARCH, PREDECESSOR, SUCCESSOR, MINI- MUM, MAXIMUM, INSERT, anddelete

More information

CSE 502 Class 16. Jeremy Buhler Steve Cole. March A while back, we introduced the idea of collections to put hash tables in context.

CSE 502 Class 16. Jeremy Buhler Steve Cole. March A while back, we introduced the idea of collections to put hash tables in context. CSE 502 Class 16 Jeremy Buhler Steve Cole March 17 2015 Onwards to trees! 1 Collection Types Revisited A while back, we introduced the idea of collections to put hash tables in context. abstract data types

More information

SFU CMPT Lecture: Week 9

SFU CMPT Lecture: Week 9 SFU CMPT-307 2008-2 1 Lecture: Week 9 SFU CMPT-307 2008-2 Lecture: Week 9 Ján Maňuch E-mail: jmanuch@sfu.ca Lecture on July 8, 2008, 5.30pm-8.20pm SFU CMPT-307 2008-2 2 Lecture: Week 9 Binary search trees

More information

Search Trees. Undirected graph Directed graph Tree Binary search tree

Search Trees. Undirected graph Directed graph Tree Binary search tree Search Trees Undirected graph Directed graph Tree Binary search tree 1 Binary Search Tree Binary search key property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then

More information

CS102 Binary Search Trees

CS102 Binary Search Trees CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one

More information

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs Algorithms in Systems Engineering ISE 172 Lecture 16 Dr. Ted Ralphs ISE 172 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms

More information

CMSC 441: Algorithms. Hillol Kargupta, Professor.

CMSC 441: Algorithms. Hillol Kargupta, Professor. CMSC 441: Algorithms Hillol Kargupta, Professor http://www.cs.umbc.edu/~hillol/ hillol@gl.umbc.edu Today s Topics Binary Search Trees Red-Black Trees Binary Search Tree Binary tree Satisfies binary-search-tree

More information

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs Computational Optimization ISE 407 Lecture 16 Dr. Ted Ralphs ISE 407 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms in

More information

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree 0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree

More information

Lecture 3: B-Trees. October Lecture 3: B-Trees

Lecture 3: B-Trees. October Lecture 3: B-Trees October 2017 Remarks Search trees The dynamic set operations search, minimum, maximum, successor, predecessor, insert and del can be performed efficiently (in O(log n) time) if the search tree is balanced.

More information

Augmenting Data Structures

Augmenting Data Structures Augmenting Data Structures Augmenting Data Structures Let s look at two new problems: Dynamic order statistic Interval search It is unusual to have to design all-new data structures from scratch Typically:

More information

CS 361, Lecture 21. Outline. Things you can do. Things I will do. Evaluation Results

CS 361, Lecture 21. Outline. Things you can do. Things I will do. Evaluation Results HW Difficulty CS 361, Lecture 21 Jared Saia University of New Mexico The HW in this class is inherently difficult, this is a difficult class. You need to be able to solve problems as hard as the problems

More information

Properties of red-black trees

Properties of red-black trees Red-Black Trees Introduction We have seen that a binary search tree is a useful tool. I.e., if its height is h, then we can implement any basic operation on it in O(h) units of time. The problem: given

More information

Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu

Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu Algorithms and Data Structures (INF1) Lecture 8/15 Hua Lu Department of Computer Science Aalborg University Fall 2007 This Lecture Trees Basics Rooted trees Binary trees Binary tree ADT Tree traversal

More information

Red-Black Trees (2) Antonio Carzaniga. April 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

Red-Black Trees (2) Antonio Carzaniga. April 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga Red-Black Trees (2) Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana April 23, 2013 Recap on Red-Black Trees 2006 Antonio Carzaniga Recap on Red-Black Trees 12 5 18 2 9 15 19

More information

Lecture 7. Binary Search Trees / AVL Trees

Lecture 7. Binary Search Trees / AVL Trees Lecture 7. Binary Searc Trees / AVL Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algoritms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Coo coo@skku.edu Copyrigt

More information

Balanced search trees

Balanced search trees Balanced search trees Ordinary binary search trees have expected height Θ(log n) if items are inserted and deleted in random order, but for other orders the height can be Θ(n). This is undesirable, since

More information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Red-Black Trees (2) Antonio Carzaniga. Faculty of Informatics University of Lugano. April 26, Antonio Carzaniga 1

Red-Black Trees (2) Antonio Carzaniga. Faculty of Informatics University of Lugano. April 26, Antonio Carzaniga 1 Red-lack Trees (2) ntonio arzaniga Faculty of Informatics University of Lugano pril 26, 2012 2006 ntonio arzaniga 1 Recap on Red-lack Trees 12 5 18 2 9 15 19 4 13 17 Red-black-tree property 2. 4. 5. 1.

More information

Binary Search Trees. Analysis of Algorithms

Binary Search Trees. Analysis of Algorithms Binary Search Trees Analysis of Algorithms Binary Search Trees A BST is a binary tree in symmetric order 31 Each node has a key and every node s key is: 19 23 25 35 38 40 larger than all keys in its left

More information

Binary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 22, Antonio Carzaniga 1

Binary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 22, Antonio Carzaniga 1 Binary Search Trees Antonio Carzaniga Faculty of Informatics University of Lugano October 22, 2008 2006 Antonio Carzaniga 1 Binary search trees Outline Randomized binary search trees 2006 Antonio Carzaniga

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

Data Structures. Dynamic Sets

Data Structures. Dynamic Sets Data Structures Binary Search Tree Dynamic Sets Elements have a key and satellite data Dynamic sets support queries such as: Search(S, k) Minimum(S) Maximum(S) Successor(S, x) Predecessor(S, x) Insert(S,

More information

Associate Professor Dr. Raed Ibraheem Hamed

Associate Professor Dr. Raed Ibraheem Hamed Associate Professor Dr. Raed Ibraheem Hamed University of Human Development, College of Science and Technology Computer Science Department 2015 2016 Department of Computer Science _ UHD 1 What this Lecture

More information

3. Fundamental Data Structures

3. Fundamental Data Structures 3. Fundamental Data Structures CH08-320201: Algorithms and Data Structures 233 Data Structures Definition (recall): A data structure is a way to store and organize data in order to facilitate access and

More information

13.4 Deletion in red-black trees

13.4 Deletion in red-black trees The operation of Deletion in a red-black tree is similar to the operation of Insertion on the tree. That is, apply the deletion algorithm for binary search trees to delete a node z; apply node color changes

More information

Data Structures and Algorithms. Werner Nutt

Data Structures and Algorithms. Werner Nutt Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Part 6 Academic Year 2011-2012 1 Acknowledgements & Copyright Notice These slides are built on top of slides developed

More information

Binary Search Trees, etc.

Binary Search Trees, etc. Chapter 12 Binary Search Trees, etc. Binary Search trees are data structures that support a variety of dynamic set operations, e.g., Search, Minimum, Maximum, Predecessors, Successors, Insert, and Delete.

More information

March 20/2003 Jayakanth Srinivasan,

March 20/2003 Jayakanth Srinivasan, Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or

More information

Problem Set 5 Solutions

Problem Set 5 Solutions Introduction to Algorithms November 4, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 21 Problem Set 5 Solutions Problem 5-1. Skip

More information

Module 4: Priority Queues

Module 4: Priority Queues Module 4: Priority Queues CS 240 Data Structures and Data Management T. Biedl K. Lanctot M. Sepehri S. Wild Based on lecture notes by many previous cs240 instructors David R. Cheriton School of Computer

More information

A set of nodes (or vertices) with a single starting point

A set of nodes (or vertices) with a single starting point Binary Search Trees Understand tree terminology Understand and implement tree traversals Define the binary search tree property Implement binary search trees Implement the TreeSort algorithm 2 A set of

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006 Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that

More information

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli 2-3 and 2-3-4 Trees COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli Multi-Way Trees A binary search tree: One value in each node At most 2 children An M-way search tree: Between 1 to (M-1) values

More information

TREES. Trees - Introduction

TREES. Trees - Introduction TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

Binary Search Trees. Motivation. Binary search tree. Tirgul 7

Binary Search Trees. Motivation. Binary search tree. Tirgul 7 Tirgul 7 Binary Search Trees Motivation We would like to have a dynamic ADT that efficiently supports the following common operations: Insert & Delete Search for an element Minimum & Maximum Predecessor

More information

Algorithms. Deleting from Red-Black Trees B-Trees

Algorithms. Deleting from Red-Black Trees B-Trees Algorithms Deleting from Red-Black Trees B-Trees Recall the rules for BST deletion 1. If vertex to be deleted is a leaf, just delete it. 2. If vertex to be deleted has just one child, replace it with that

More information

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

2-3 Tree. Outline B-TREE. catch(...){ printf( Assignment::SolveProblem() AAAA!); } ADD SLIDES ON DISJOINT SETS Outline catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } Balanced Search Trees 2-3 Trees 2-3-4 Trees Slide 4 Why care about advanced implementations? Same entries, different insertion sequence:

More information

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black. Outline 1 Definition Computer Science 331 Red-Black rees Mike Jacobson Department of Computer Science University of Calgary Lectures #20-22 2 Height-Balance 3 Searches 4 Rotations 5 s: Main Case 6 Partial

More information

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2008S-19 B-Trees David Galles Department of Computer Science University of San Francisco 19-0: Indexing Operations: Add an element Remove an element Find an element,

More information

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

ADVANCED DATA STRUCTURES

ADVANCED DATA STRUCTURES ADVANCED DATA STRUCTURES Lecture 1 Introduction. Binary search trees. Efficiency issues Mircea Marin mircea.marin@e-uvt.ro Organizatorial items Lecturer and Teaching Assistant: Mircea Marin email: mircea.marin@e-uvt.ro

More information

Geometric Data Structures

Geometric Data Structures Geometric Data Structures 1 Data Structure 2 Definition: A data structure is a particular way of organizing and storing data in a computer for efficient search and retrieval, including associated algorithms

More information

Search Trees: BSTs and B-Trees

Search Trees: BSTs and B-Trees 3//13 Search Trees: BSTs and B-Trees Administrative David Kauchak cs302 Spring 13 Proof by contradiction Number guessing game I m thinking of a number between 1 and n You are trying to guess the answer

More information

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees Outline General Trees Terminology, Representation, Properties Binary Trees Representations, Properties, Traversals Recursive Algorithms

More information

Heap Order Property: Key stored at the parent is smaller or equal to the key stored at either child.

Heap Order Property: Key stored at the parent is smaller or equal to the key stored at either child. A Binary Heap is a data structure that is an array object that can be viewed as a nearly complete binary tree. The tree is completely filled on all levels except the lowest, which may only be partially

More information

9/24/ Hash functions

9/24/ Hash functions 11.3 Hash functions A good hash function satis es (approximately) the assumption of SUH: each key is equally likely to hash to any of the slots, independently of the other keys We typically have no way

More information

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department Abstract Data Structures IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4: Computational

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS62: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Binary Search Tree - Best Time All BST operations are O(d), where d is tree depth minimum d is d = ëlog for a binary tree

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS62: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Balanced search trees Balanced search tree: A search-tree data structure for which a height of O(lg n) is guaranteed when

More information

13.4 Deletion in red-black trees

13.4 Deletion in red-black trees Deletion in a red-black tree is similar to insertion. Apply the deletion algorithm for binary search trees. Apply node color changes and left/right rotations to fix the violations of RBT tree properties.

More information

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr mahmoud.sakr@cis.asu.edu.eg Cairo, Egypt, October 2012 Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to root

More information

CS24 Week 8 Lecture 1

CS24 Week 8 Lecture 1 CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes

More information

Searching: Introduction

Searching: Introduction Searching: Introduction Searching is a major topic in data structures and algorithms Applications: Search for students transcripts from ARR Search for faculty contact email address, office Search for books,

More information

18. Binary Search Trees

18. Binary Search Trees Trees. Binary Search Trees [Ottman/Widmayer, Kap..1, Cormen et al, Kap. 12.1-12.] Trees are Generalized lists: nodes can have more than one successor Special graphs: graphs consist of nodes and edges.

More information

18.3 Deleting a key from a B-tree

18.3 Deleting a key from a B-tree 18.3 Deleting a key from a B-tree B-TREE-DELETE deletes the key from the subtree rooted at We design it to guarantee that whenever it calls itself recursively on a node, the number of keys in is at least

More information

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min Binary Search Trees FRIDAY ALGORITHMS Sorted Arrays Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min 6 10 11 17 2 0 6 Running Time O(1) O(lg n) O(1) O(1)

More information

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging. Priority Queue, Heap and Heap Sort In this time, we will study Priority queue, heap and heap sort. Heap is a data structure, which permits one to insert elements into a set and also to find the largest

More information

arxiv: v1 [cs.ds] 13 Jul 2009

arxiv: v1 [cs.ds] 13 Jul 2009 Layered Working-Set Trees Prosenjit Bose Karim Douïeb Vida Dujmović John Howat arxiv:0907.2071v1 [cs.ds] 13 Jul 2009 Abstract The working-set bound [Sleator and Tarjan, J. ACM, 1985] roughly states that

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Binary Search Trees CLRS 12.2, 12.3, 13.2, read problem 13-3 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures

More information

1 B + tree. 1.1 Definition. 1.2 Searching. 1

1 B + tree. 1.1 Definition. 1.2 Searching.   1 www.alepho.com 1 1 B + tree Motivation for B + tree is to have data structure with the properties as for B tree, while keys can be accessed in batches. Thus, for each key the adjacent keys can be found

More information

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides Jana Kosecka Red-Black Trees Graph Algorithms Many slides here are based on E. Demaine, D. Luebke slides Binary Search Trees (BSTs) are an important data structure for dynamic sets In addition to satellite

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced 13 Red-Black Trees A red-black tree (RBT) is a BST with one extra bit of storage per node: color, either RED or BLACK Constraining the node colors on any path from the root to a leaf Ensures that no such

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 25 Fall 2018 Instructor: B 2

CSCI 136 Data Structures & Advanced Programming. Lecture 25 Fall 2018 Instructor: B 2 CSCI 136 Data Structures & Advanced Programming Lecture 25 Fall 2018 Instructor: B 2 Last Time Binary search trees (Ch 14) The locate method Further Implementation 2 Today s Outline Binary search trees

More information