SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
UNIT III NON LINEAR DATA STRUCTURES – TREES
UNIT III 	NON LINEAR DATA STRUCTURES – TREESUNIT III 	NON LINEAR DATA STRUCTURES – TREES
UNIT III NON LINEAR DATA STRUCTURES – TREES
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Disjoint sets union, find
Disjoint sets  union, findDisjoint sets  union, find
Disjoint sets union, find
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptx
 
B tree
B treeB tree
B tree
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
B trees dbms
B trees dbmsB trees dbms
B trees dbms
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
 
B tree
B treeB tree
B tree
 
b+ tree
b+ treeb+ tree
b+ tree
 
05 Clustering in Data Mining
05 Clustering in Data Mining05 Clustering in Data Mining
05 Clustering in Data Mining
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 

Similar a 2 3 tree

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 knowLittbarski Santos
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptxujjwalmatoliya
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMSMathkeBhoot
 
Lecture notes data structures tree
Lecture notes data structures   treeLecture notes data structures   tree
Lecture notes data structures treemaamir farooq
 
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 BSTsAmrinder Arora
 

Similar a 2 3 tree (8)

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++
 
B TREE ( a to z concept ) in data structure or DBMS
B TREE ( a to z concept ) in data structure  or DBMSB TREE ( a to z concept ) in data structure  or DBMS
B TREE ( a to z concept ) in data structure or DBMS
 
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
 

Más 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

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Último (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

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 del editor

  1. {}