SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
ghhgj jhgh
 

Tendances (20)

Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Red black trees
Red black treesRed black trees
Red black trees
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Red black trees
Red black treesRed black trees
Red black trees
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
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
 
Linked lists
Linked listsLinked lists
Linked lists
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
 
Red black tree
Red black treeRed black tree
Red black tree
 
Binary tree traversal ppt
Binary tree traversal pptBinary tree traversal ppt
Binary tree traversal ppt
 
B tree
B treeB tree
B tree
 

Similaire à 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
 

Similaire à 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
 

Plus de Anju Kanjirathingal

Plus 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
 

Dernier

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Dernier (20)

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).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
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

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

Notes de l'éditeur

  1. {}