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

What's hot

Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
Dexter Paul Gumahad
 
Discrete mathematics
Discrete mathematicsDiscrete mathematics
Discrete mathematics
tawhid98
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
Piotr Szymański
 
Red black tree
Red black treeRed black tree
Red black tree
qamar mustafa
 
Red black tree
Red black treeRed black tree
Red black tree
uos lahore
 
Lesson 1 3 exponents
Lesson 1 3 exponentsLesson 1 3 exponents
Lesson 1 3 exponents
mlabuski
 
Laws of exponents complete
Laws of exponents   completeLaws of exponents   complete
Laws of exponents complete
nyambi james
 

What's hot (7)

Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
 
Discrete mathematics
Discrete mathematicsDiscrete mathematics
Discrete mathematics
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Red black tree
Red black treeRed black tree
Red black tree
 
Red black tree
Red black treeRed black tree
Red black tree
 
Lesson 1 3 exponents
Lesson 1 3 exponentsLesson 1 3 exponents
Lesson 1 3 exponents
 
Laws of exponents complete
Laws of exponents   completeLaws of exponents   complete
Laws of exponents complete
 

Viewers also liked

2-3 Tree
2-3 Tree2-3 Tree
2 3 tree
2 3 tree2 3 tree
2 - 3 Trees
2 - 3 Trees2 - 3 Trees
2 - 3 Trees
vikram singh
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
Core Condor
 
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
Intracellular highways in the plants:  the role of the cytoskeleton in camv i...Intracellular highways in the plants:  the role of the cytoskeleton in camv i...
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
CIAT
 
Plant virus
Plant virusPlant virus
Plant virus
Pawan Kumar
 
Cauliflower mosaic virus
Cauliflower mosaic virusCauliflower mosaic virus
Cauliflower mosaic virus
Padmaratinam
 

Viewers also liked (7)

2-3 Tree
2-3 Tree2-3 Tree
2-3 Tree
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
2 - 3 Trees
2 - 3 Trees2 - 3 Trees
2 - 3 Trees
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
Intracellular highways in the plants:  the role of the cytoskeleton in camv i...Intracellular highways in the plants:  the role of the cytoskeleton in camv i...
Intracellular highways in the plants: the role of the cytoskeleton in camv i...
 
Plant virus
Plant virusPlant virus
Plant virus
 
Cauliflower mosaic virus
Cauliflower mosaic virusCauliflower mosaic virus
Cauliflower mosaic virus
 

Similar to 23 Tree Best Part

Trees ayaz
Trees ayazTrees ayaz
Trees ayaz
Ayaz Shariff
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_trees
Nathan Gabriel
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
AnuradhaJadiya1
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementation
Umang Gupta
 
Tree
TreeTree
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
SSE_AndyLi
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
DhanushSrinivasulu
 
My Presentation on Row Sums of Calkin-Wilf Trees
My Presentation on Row Sums of Calkin-Wilf TreesMy Presentation on Row Sums of Calkin-Wilf Trees
My Presentation on Row Sums of Calkin-Wilf Trees
Stephanie Lu
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
sumitbardhan
 
Tree
TreeTree
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
Abirami A
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
Hanif Durad
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
Parthipan Parthi
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
worldchannel
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5
DrkhanchanaR
 
Trees
TreesTrees
Btree
BtreeBtree
Data structures
Data structuresData structures
Data structures
IIUI
 

Similar to 23 Tree Best Part (20)

Trees ayaz
Trees ayazTrees ayaz
Trees ayaz
 
Pattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_treesPattern_avoidance_in_ternary_trees
Pattern_avoidance_in_ternary_trees
 
Module - 5_Trees.pdf
Module - 5_Trees.pdfModule - 5_Trees.pdf
Module - 5_Trees.pdf
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementation
 
Tree
TreeTree
Tree
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
Binary tree
Binary treeBinary tree
Binary tree
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
My Presentation on Row Sums of Calkin-Wilf Trees
My Presentation on Row Sums of Calkin-Wilf TreesMy Presentation on Row Sums of Calkin-Wilf Trees
My Presentation on Row Sums of Calkin-Wilf Trees
 
358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Tree
TreeTree
Tree
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Unit 3 Tree chapter 5
Unit 3  Tree chapter 5Unit 3  Tree chapter 5
Unit 3 Tree chapter 5
 
Trees
TreesTrees
Trees
 
Btree
BtreeBtree
Btree
 
Data structures
Data structuresData structures
Data structures
 

More from vikram singh

Agile
AgileAgile
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
vikram singh
 
Web tech importants
Web tech importantsWeb tech importants
Web tech importants
vikram singh
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
vikram singh
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
vikram singh
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharing
vikram singh
 
Bean Intro
Bean IntroBean Intro
Bean Intro
vikram singh
 
jdbc
jdbcjdbc
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
vikram singh
 
Xml
XmlXml
Dtd
DtdDtd
Xml Schema
Xml SchemaXml Schema
Xml Schema
vikram singh
 
JSP
JSPJSP
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
vikram singh
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
vikram singh
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
vikram singh
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
vikram singh
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh
 

More from vikram singh (20)

Agile
AgileAgile
Agile
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Web tech importants
Web tech importantsWeb tech importants
Web tech importants
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharing
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
jdbc
jdbcjdbc
jdbc
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
 
Xml
XmlXml
Xml
 
Dtd
DtdDtd
Dtd
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
JSP
JSPJSP
JSP
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 

Recently uploaded

Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 

Recently uploaded (20)

Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 

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
  • 4.
  • 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.