SlideShare uma empresa Scribd logo
1 de 24
Submitted By :
Anju George.K
Submitted To :
Miss.Betzy
Date : 25/01/2013
INTRODUCTION

 What Is a 2-3 Tree?
 Definition: A 2-3 tree is a tree in which each internal
node(nonleaf) has either 2 or 3 children, and all
leaves are at the same level.
2-3 Trees
 a node may contain 1 or 2 keys
 all leaf nodes are at the same depth
 all non-leaf nodes (except the root) have either 1 key
and two subtrees, or 2 keys and three subtrees
 insertion is at the leaf: if the leaf overflows, split it into
two leaves, insert them into the parent, which may also
overflow
 deletion is at the leaf: if the leaf underflows (has no
items), merge it with a sibling, removing a value and
subtree from the parent, which may also underflow
 the only changes in depth are when the root splits or
underflows
2-3 Tree of height 3
Example of a 2-3 Tree

 The items in the 2-3 are ordered by their search keys.
50

70

20

10

30

90

40

60

120

80

100

110

150

160
The Advantages of the 2-3
trees



 Even though searching a 2-3 tree is not more efficient
than searching a binary search tree, by allowing the
node of a 2-3 tree to have three children, a 2-3 tree
might be shorter than the shortest possible binary
search tree.
 Maintaining the balance of a 2-3 tree is relatively
simple than maintaining the balance of a binary
search tree .
Inserting into a 2-3 Tree

 Perform a sequence of insertions on a 2-3 tree is more
easilier to maintain the balance than in binary search
tree.
 Example:
60
90

30
30

50
40

20

80

100

70

39
38
37
36
35
34

The binary search tree after a sequence of
insertions
The Insertion Algorithm

 To insert an item I into a 2-3 tree, first locate the leaf
at which the search for I would terminate.
 Insert the new item I into the leaf.
 If the leaf now contains only two items, you are
done. If the leaf contains three items, you must split
it.
The Insertion Algorithm
(cont.)



 Spliting a leaf
a)

P

S M

L

b)

M

P

S

P

L
P

S M

L

M

S

L
Inserting into a 2-3 Tree
(cont.)



 Insert 39. The search for 39 terminates at the leaf
<40>. Since this node contains only one item, can
simply insert the new item into this node
50
70

30
10
20

39

40

60

90
80

100
Inserting into a 2-3 Tree
(cont.)



 Insert 38: The search terminates at <39 40>. Since a
node cannot have three values, we divide these three
values into smallest(38), middle(39), and largest(40)
values. Now, we move the (39) up to the node’s
parent.
30

10

20

39

38

40
Inserting into a 2-3 Tree
(cont.)



 Insert 37: It’s easy since 37 belongs in a leaf that
currently contains only one values, 38.
30

10

20

37

39

38

40
Deleting from a 2-3 Tree

 The deletion strategy for a 2-3 tree is the inverse of its
insertion strategy. Just as a 2-3 tree spreads insertions
throughout the tree by splitting nodes when they
become too full, it spreads deletions throughout the
tree by merging nodes when they become empty.
 Example:
Deleting from a 2-3 Tree
(cont.)

 Delete 70
80
60

80

90
100

70

Swap with inorder successor
80
60

90
100

60

90

-

100

Delete value from leaf
90
60

80

100

Merge nodes by deleting empty leaf and moving 80 down
Deleting from 2-3 Tree
(cont.)

 Delete 70
50
90

30

10

20

40

60

80

100
Deleting from 2-3 Tree
(cont.)

 Delete 100
90
60
60

80

80

90
--

Delete value from leaf

60

80

Doesn’t work

60

90
Redistribute

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Red black trees
Red black treesRed black trees
Red black trees
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Binary tree
Binary tree Binary tree
Binary tree
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data Structure
 
Tree
TreeTree
Tree
 
Search tree,Tree and binary tree and heap tree
Search tree,Tree  and binary tree and heap treeSearch tree,Tree  and binary tree and heap tree
Search tree,Tree and binary tree and heap tree
 
Splay Tree Algorithm
Splay Tree AlgorithmSplay Tree Algorithm
Splay Tree Algorithm
 
linked list
linked listlinked list
linked list
 
AVL tree animation.ppt
AVL tree animation.pptAVL tree animation.ppt
AVL tree animation.ppt
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Binary tree
Binary treeBinary tree
Binary tree
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Heap sort
Heap sortHeap sort
Heap sort
 
B tree
B  treeB  tree
B tree
 
Avl trees
Avl treesAvl trees
Avl trees
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 

Semelhante a 2 3 tree

2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
ujjwalmatoliya
 

Semelhante a 2 3 tree (7)

Ch16
Ch16Ch16
Ch16
 
2-3 Tree, Everything you need to know
2-3 Tree,  Everything you need to know2-3 Tree,  Everything you need to know
2-3 Tree, Everything you need to know
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
 
Binary tree
Binary treeBinary tree
Binary tree
 
2-3 trees in c++
2-3 trees in c++2-3 trees in c++
2-3 trees in c++
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures tree
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
 

Mais de Anju Kanjirathingal

Mais de Anju Kanjirathingal (9)

Java withrealworldtechnology
Java withrealworldtechnologyJava withrealworldtechnology
Java withrealworldtechnology
 
resolution in the propositional calculus
resolution in the propositional calculusresolution in the propositional calculus
resolution in the propositional calculus
 
The propositional calculus
The propositional calculusThe propositional calculus
The propositional calculus
 
microprocessor
microprocessormicroprocessor
microprocessor
 
int 21 h for screen display
int 21 h for screen displayint 21 h for screen display
int 21 h for screen display
 
int 21,16,09 h
int 21,16,09 hint 21,16,09 h
int 21,16,09 h
 
Intel 80286
Intel 80286Intel 80286
Intel 80286
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
TCP/IP
TCP/IPTCP/IP
TCP/IP
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

2 3 tree

  • 1. Submitted By : Anju George.K Submitted To : Miss.Betzy Date : 25/01/2013
  • 2. INTRODUCTION   What Is a 2-3 Tree?  Definition: A 2-3 tree is a tree in which each internal node(nonleaf) has either 2 or 3 children, and all leaves are at the same level.
  • 3. 2-3 Trees  a node may contain 1 or 2 keys  all leaf nodes are at the same depth  all non-leaf nodes (except the root) have either 1 key and two subtrees, or 2 keys and three subtrees  insertion is at the leaf: if the leaf overflows, split it into two leaves, insert them into the parent, which may also overflow  deletion is at the leaf: if the leaf underflows (has no items), merge it with a sibling, removing a value and subtree from the parent, which may also underflow  the only changes in depth are when the root splits or underflows
  • 4. 2-3 Tree of height 3
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Example of a 2-3 Tree   The items in the 2-3 are ordered by their search keys. 50 70 20 10 30 90 40 60 120 80 100 110 150 160
  • 10. The Advantages of the 2-3 trees   Even though searching a 2-3 tree is not more efficient than searching a binary search tree, by allowing the node of a 2-3 tree to have three children, a 2-3 tree might be shorter than the shortest possible binary search tree.  Maintaining the balance of a 2-3 tree is relatively simple than maintaining the balance of a binary search tree .
  • 11. Inserting into a 2-3 Tree   Perform a sequence of insertions on a 2-3 tree is more easilier to maintain the balance than in binary search tree.  Example:
  • 13. The Insertion Algorithm   To insert an item I into a 2-3 tree, first locate the leaf at which the search for I would terminate.  Insert the new item I into the leaf.  If the leaf now contains only two items, you are done. If the leaf contains three items, you must split it.
  • 14. The Insertion Algorithm (cont.)   Spliting a leaf a) P S M L b) M P S P L P S M L M S L
  • 15. Inserting into a 2-3 Tree (cont.)   Insert 39. The search for 39 terminates at the leaf <40>. Since this node contains only one item, can simply insert the new item into this node 50 70 30 10 20 39 40 60 90 80 100
  • 16. Inserting into a 2-3 Tree (cont.)   Insert 38: The search terminates at <39 40>. Since a node cannot have three values, we divide these three values into smallest(38), middle(39), and largest(40) values. Now, we move the (39) up to the node’s parent. 30 10 20 39 38 40
  • 17. Inserting into a 2-3 Tree (cont.)   Insert 37: It’s easy since 37 belongs in a leaf that currently contains only one values, 38. 30 10 20 37 39 38 40
  • 18.
  • 19.
  • 20.
  • 21. Deleting from a 2-3 Tree   The deletion strategy for a 2-3 tree is the inverse of its insertion strategy. Just as a 2-3 tree spreads insertions throughout the tree by splitting nodes when they become too full, it spreads deletions throughout the tree by merging nodes when they become empty.  Example:
  • 22. Deleting from a 2-3 Tree (cont.)   Delete 70 80 60 80 90 100 70 Swap with inorder successor 80 60 90 100 60 90 - 100 Delete value from leaf 90 60 80 100 Merge nodes by deleting empty leaf and moving 80 down
  • 23. Deleting from 2-3 Tree (cont.)   Delete 70 50 90 30 10 20 40 60 80 100
  • 24. Deleting from 2-3 Tree (cont.)   Delete 100 90 60 60 80 80 90 -- Delete value from leaf 60 80 Doesn’t work 60 90 Redistribute

Notas do Editor

  1. {}