SlideShare a Scribd company logo
5.3 2-3 Trees
Definition

    •   A 2-3 Tree is a null tree (zero nodes) or a single node tree (only one node) or a
        multiple node tree with the following properties:

        1.
        Each interior node has two or three children
        2.
        Each path from the root to a leaf has the same length.
Fields of a Node :

Internal Node

p1 k1 p2 k2 p3
  p1 : Pointer to the first child
  p2 : Pointer to the second child
  p3 : Pointer to the third child
  k1 : Smallest key that is a descendent of the second child
  k2 : Smallest key that is a descendent of the third child

Leaf Node

key other fields


   Records are placed at the leaves. Each leaf contains a record (and key)

Example: See Figure 5.23



                          Figure 5.23: An example of a 2-3 tree
Search

   •     The values recorded at the internal nodes can be used to guide the search path.
   •     To search for a record with key value x, we first start at the root. Let k1 and k2 be
         the two values stored here.

         1.
         If x < k1, move to the first child
         2.

         If x    k1 and the node has only two children, move to the second child
         3.

         If x    k1 and the node has three children, move to the second child if x < k2 and

         to the third child if x     k2.

   •     Eventually, we reach a leaf. x is in the tree iff x is at this leaf.

Path Lengths

   •     A 2-3 Tree with k levels has between 2k - 1 and 3k - 1 leaves
   •     Thus a 2-3 tree with n elements (leaves) requires


         at least 1 + log3n levels

         at most 1 + log2n levels

5.3.1 2-3 Trees: Insertion

For an example, see Figure 5.24.
Figure 5.24: Insertion in 2-3 trees: An example




Figure 5.25: Deletion in 2-3 trees: An Example
23 Tree   Best Part
Insert (x)

1.
       Locate the node v, which should be the parent of x
2.
       If v has two children,

             •   make x another child of v and place it in the proper order
             •   adjust k1 and k2 at node v to reflect the new situation

3.
       If v has three children,

             •   split v into two nodes v and v'. Make the two smallest among four children
                 stay with v and assign the other two as children of v'.
             •   Recursively insert v' among the children of w where

                                                w = parent of v

             •   The recursive insertion can proceed all the way up to the root, making it
                 necessary to split the root. In this case, create a new root, thus increasing
                 the number of levels by 1.

5.3.2 2-3 Trees: Deletion

Delete (x)

1.
       Locate the leaf L containing x and let v be the parent of L
2.
       Delete L. This may leave v with only one child. If v is the root, delete v and let its
       lone child become the new root. This reduces the number of levels by 1. If v is not
       the root, let
       p = parent of v
       If p has a child with 3 children, transfer an appropriate one to vif this child is
       adjacent (sibling) to v.
       If children of p adjacent to v have only two children, transfer the lone child of v to
       an adjacent sibling of v and delete v.

             •   If p now has only one child, repeat recursively with p in place of v. The
                 recursion can ripple all the way up to the root, leading to a decrease in the
                 number of levels.

Example: See Figure 5.25.

More Related Content

PPTX
Lecture 7 bst
DOCX
Lesson 4 5 equivalent fractions
DOCX
Unit 5 lesson 2 equivalent fractions
PDF
Exponents.Test.Slide.Show
PDF
Topic 4 dividing a polynomial by a monomial
PPT
Red black tree
PPT
Chapter 1.3
Lecture 7 bst
Lesson 4 5 equivalent fractions
Unit 5 lesson 2 equivalent fractions
Exponents.Test.Slide.Show
Topic 4 dividing a polynomial by a monomial
Red black tree
Chapter 1.3

What's hot (7)

PPT
Red black trees presentation
PPTX
Discrete mathematics
PPT
Red Black Trees
PPTX
Red black tree
PDF
Red black tree
DOC
Lesson 1 3 exponents
PPT
Laws of exponents complete
Red black trees presentation
Discrete mathematics
Red Black Trees
Red black tree
Red black tree
Lesson 1 3 exponents
Laws of exponents complete
Ad

Viewers also liked (7)

PPT
PDF
2 - 3 Trees
PPT
2 3 tree
PPTX
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
PPSX
Plant virus
PPTX
Cauliflower mosaic virus
2 - 3 Trees
2 3 tree
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
Plant virus
Cauliflower mosaic virus
Ad

Similar to 23 Tree Best Part (20)

PPT
Unit 8
PPTX
PPTX
Tree all information about tree concept are available .
PPT
Data structures
PDF
Module - 5_Trees.pdf
PPTX
CHAPTER 5 TREE Student.pptxlllllllllllllllllllllllllll
PPT
358 33 powerpoint-slides_10-trees_chapter-10
PPTX
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
PPT
Binary trees
PPTX
Data structure using c module 2
PPTX
2-3 Tree, Everything you need to know
PPTX
Introduction to tree ds
PPTX
TreesTreesTreesTreesTreesTreesTrees.pptx
PPT
DOCX
Abstract idea of a tree
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Tree data structure.pptx
PPTX
Introduction to Tree_Data Structure.pptx
Unit 8
Tree all information about tree concept are available .
Data structures
Module - 5_Trees.pdf
CHAPTER 5 TREE Student.pptxlllllllllllllllllllllllllll
358 33 powerpoint-slides_10-trees_chapter-10
TERMINOLOGIES OF TREE, TYPES OF TREE.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
Binary trees
Data structure using c module 2
2-3 Tree, Everything you need to know
Introduction to tree ds
TreesTreesTreesTreesTreesTreesTrees.pptx
Abstract idea of a tree
BINARY TREE REPRESENTATION.ppt
Tree data structure.pptx
Introduction to Tree_Data Structure.pptx

More from vikram singh (20)

PPTX
PPT
Enterprise java beans(ejb) Update 2
PDF
Web tech importants
PPT
Enterprise Java Beans( E)
PPT
Enterprise java beans(ejb) update 2
PPT
Enterprise java beans(ejb)
DOC
2 4 Tree
DOC
JSP Scope variable And Data Sharing
PPT
Bean Intro
PPT
PPT
Sax Dom Tutorial
PPT
PPT
PPT
Xml Schema
PPT
PPT
Request dispatching in servlet
PPT
Servlet Part 2
DOC
Tutorial Solution
DOC
Java Script Language Tutorial
PPT
Web Tech Java Servlet Update1
Enterprise java beans(ejb) Update 2
Web tech importants
Enterprise Java Beans( E)
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb)
2 4 Tree
JSP Scope variable And Data Sharing
Bean Intro
Sax Dom Tutorial
Xml Schema
Request dispatching in servlet
Servlet Part 2
Tutorial Solution
Java Script Language Tutorial
Web Tech Java Servlet Update1

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Modernizing your data center with Dell and AMD
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The AUB Centre for AI in Media Proposal.docx
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Modernizing your data center with Dell and AMD
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Understanding_Digital_Forensics_Presentation.pptx

23 Tree Best Part

  • 1. 5.3 2-3 Trees Definition • A 2-3 Tree is a null tree (zero nodes) or a single node tree (only one node) or a multiple node tree with the following properties: 1. Each interior node has two or three children 2. Each path from the root to a leaf has the same length. Fields of a Node : Internal Node p1 k1 p2 k2 p3 p1 : Pointer to the first child p2 : Pointer to the second child p3 : Pointer to the third child k1 : Smallest key that is a descendent of the second child k2 : Smallest key that is a descendent of the third child Leaf Node key other fields Records are placed at the leaves. Each leaf contains a record (and key) Example: See Figure 5.23 Figure 5.23: An example of a 2-3 tree
  • 2. Search • The values recorded at the internal nodes can be used to guide the search path. • To search for a record with key value x, we first start at the root. Let k1 and k2 be the two values stored here. 1. If x < k1, move to the first child 2. If x k1 and the node has only two children, move to the second child 3. If x k1 and the node has three children, move to the second child if x < k2 and to the third child if x k2. • Eventually, we reach a leaf. x is in the tree iff x is at this leaf. Path Lengths • A 2-3 Tree with k levels has between 2k - 1 and 3k - 1 leaves • Thus a 2-3 tree with n elements (leaves) requires at least 1 + log3n levels at most 1 + log2n levels 5.3.1 2-3 Trees: Insertion For an example, see Figure 5.24.
  • 3. Figure 5.24: Insertion in 2-3 trees: An example Figure 5.25: Deletion in 2-3 trees: An Example
  • 5. Insert (x) 1. Locate the node v, which should be the parent of x 2. If v has two children, • make x another child of v and place it in the proper order • adjust k1 and k2 at node v to reflect the new situation 3. If v has three children, • split v into two nodes v and v'. Make the two smallest among four children stay with v and assign the other two as children of v'. • Recursively insert v' among the children of w where w = parent of v • The recursive insertion can proceed all the way up to the root, making it necessary to split the root. In this case, create a new root, thus increasing the number of levels by 1. 5.3.2 2-3 Trees: Deletion Delete (x) 1. Locate the leaf L containing x and let v be the parent of L 2. Delete L. This may leave v with only one child. If v is the root, delete v and let its lone child become the new root. This reduces the number of levels by 1. If v is not the root, let p = parent of v If p has a child with 3 children, transfer an appropriate one to vif this child is adjacent (sibling) to v. If children of p adjacent to v have only two children, transfer the lone child of v to an adjacent sibling of v and delete v. • If p now has only one child, repeat recursively with p in place of v. The recursion can ripple all the way up to the root, leading to a decrease in the number of levels. Example: See Figure 5.25.