2-3 Trees: Balanced Search Tree Data Structure - Prof. Tianming Liu, Study notes of Data Structures and Algorithms

An overview of 2-3 trees, a balanced search tree data structure. The features and benefits of 2-3 trees, including their ease of keeping the tree balanced, and provides examples of inserting and deleting items. The document also compares 2-3 trees to binary search trees.

Typology: Study notes

2011/2012

Uploaded on 04/09/2012

manan-1
manan-1 🇺🇸

1 document

1 / 39

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Tianming Liu
Department of Computer Science & Bioimaging Research Center
The University of Georgia
Lecture 20: 2-3 Tree
CSCI 2720:
Data Structures
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download 2-3 Trees: Balanced Search Tree Data Structure - Prof. Tianming Liu and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Tianming Liu

Department of Computer Science & Bioimaging Research Center

The University of Georgia

Lecture 20: 2-3 Tree CSCI 2720: Data Structures

Slides Courtesy: Eileen Kraemer

Why care about advanced implementations?

Same entries, different insertion sequence:

 Not good! Would like to keep tree balanced.

2-3 Trees

 each internal node has either 2 or 3 children

 all leaves are at the same level

Features

Example of 2-3 Tree

Traversing a 2-3 Tree

inorder (in ttTree: TwoThreeTree) if (ttTree’s root node r is a leaf) visit the data item(s) else if (r has two data items) { inorder(left subtree of ttTree’s root) visit the first data item inorder(middle subtree of ttTree’s root) visit the second data item inorder(right subtree of ttTree’s root) } else { inorder(left subtree of ttTree’s root) visit the data item inorder(right subtree of ttTree’s root) }

Gain: Ease of Keeping the Tree Balanced

Binary Search

Tree

2-3 Tree

both trees after

inserting items

Inserting Items

Insert 39

Inserting Items

Insert 37

Inserting Items

Insert 36

insert in leaf divide leaf and move middle value up to parent overcrowded node

Inserting Items

After Insertion of 35, 34, 33

Inserting so far

Inserting Items

 creating a new root if necessary

 tree grows at the root

Inserting Items

How do we insert 3 2?