SlideShare a Scribd company logo
1 of 13
Red-Black Trees

Niño Guerrero
Dexter Paul Gumahad
Rene Madera
Reymart Pagente
Data Structure || JRMSU Computer Science
Red-Black Trees
• A Red-Black tree is a binary search tree with
these traits:
– Every node is either red or black.
– The root is always black.
– If a node is red, its children must be black.
– Every path from any node to a null must have the
same number of black nodes.

• Operations on Red-Black trees are O(log N).
Data Structure || JRMSU Computer Science
Red-Black tree
c

a

f

b

d

g

e

Data Structure || JRMSU Computer Science
Red-Black Trees
• Red-black trees can be thought of as binary
tree representations of a 2-3-4 tree.
• A 2-3-4 tree is a B-tree of degree 4.
• This means each internal node has either 2, 3,
or 4 children.
• The next slide illustrates this.

Data Structure || JRMSU Computer Science
2-3-4 tree

c

a

b

f

d

e

Data Structure || JRMSU Computer Science

g
How the Trees Relate
c

c

a

f

d

e

f
a
b

d

b

g

g

e

Each black node represents a node in the 2-3-4 tree.
Each red node is in the same node with its black parent.
This explains why every path has the same number of black nodes.
Data Structure || JRMSU Computer Science
Mappings
a

a

b

a
or
a

b

a

b

b
a

b

c
a
Data Structure || JRMSU Computer Science

c
Inserting into a Red-Black Tree
• An inserted node is placed as in a binary
search tree as a red node, unless it is the root.
• If the parent of the new node is also red,
called a “double red”, the tree will have to be
adjusted, since a red child must have a black
parent.

Data Structure || JRMSU Computer Science
Two Cases
1.

a

u

w

c
b

2.

a

Inserting node z causes double red,
and z’s parent has black sibling w.
This occurs when a 4-node is
malformed: must restructure.

v

z

u
c

w
b

z

v

Inserting node z causes double red,
and z’s parent has red sibling w.
This occurs when a 4-node
overflows: must recolor.
Note: these are partial trees so not all
Data Structure || JRMSU Computer subtrees are shown.
of their Science
Restructuring
a

c

w

c

w

a

b

a
w

c
b

b
c

b

Double rotation

w

a

Single rotation

b

The malformed 4-node is
now a well-formed 4-node.

a

c

Data Structure || JRMSU Computer Science

Parent is black,
children are red.
Recoloring
b

b
w

d

a

w

d

a
c

c

b
w

a

b
c

w

a

d

Note: since b is now red, this can cause a double red with b’s parent.
If so, the two cases are considered again for Science its parent.
Data Structure || JRMSU Computer b and

c
d
Example
e

e

e
h

h
k

1. Insert e

2. Insert h

h

h

e

k

e

3. Insert k, h has
null (black) sibling
h
e

k
n

4. Restructure

5. Insert n, k has
red sibling
Data Structure || JRMSU Computer Science

k
n

6. Recolor (root left
black)
End

Data Structure || JRMSU Computer Science

More Related Content

What's hot

Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sortKrish_ver2
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionHAMID-50
 
File organisation in system analysis and design
File organisation in system analysis and designFile organisation in system analysis and design
File organisation in system analysis and designMohitgauri
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Abhimanyu Mishra
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Himanshu Choudhary
 
Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)Niloy Biswas
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
Introduction to Automata Languages and Computation
Introduction to Automata Languages and ComputationIntroduction to Automata Languages and Computation
Introduction to Automata Languages and ComputationAmey Kerkar
 
Red black tree insertion
Red black tree insertionRed black tree insertion
Red black tree insertionKousalya M
 

What's hot (20)

Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Red black tree
Red black treeRed black tree
Red black tree
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 
File organisation in system analysis and design
File organisation in system analysis and designFile organisation in system analysis and design
File organisation in system analysis and design
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Red black tree
Red black treeRed black tree
Red black tree
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
 
Lecture24
Lecture24Lecture24
Lecture24
 
Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Introduction to Automata Languages and Computation
Introduction to Automata Languages and ComputationIntroduction to Automata Languages and Computation
Introduction to Automata Languages and Computation
 
Red black tree insertion
Red black tree insertionRed black tree insertion
Red black tree insertion
 

Viewers also liked

Viewers also liked (20)

Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
10 Red-Black Trees
10 Red-Black Trees10 Red-Black Trees
10 Red-Black Trees
 
Algebra 1 2.8 Algebraic Proof
Algebra 1 2.8 Algebraic ProofAlgebra 1 2.8 Algebraic Proof
Algebra 1 2.8 Algebraic Proof
 
Insertion in RED BLACK TREE
Insertion in RED BLACK TREEInsertion in RED BLACK TREE
Insertion in RED BLACK TREE
 
Struktur data 06 (red black tree)
Struktur data 06 (red black tree)Struktur data 06 (red black tree)
Struktur data 06 (red black tree)
 
Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)Splay trees by NIKHIL ARORA (www.internetnotes.in)
Splay trees by NIKHIL ARORA (www.internetnotes.in)
 
Logic gates with laws
Logic gates with lawsLogic gates with laws
Logic gates with laws
 
Red black trees1109
Red black trees1109Red black trees1109
Red black trees1109
 
B-Tree
B-TreeB-Tree
B-Tree
 
B tree long
B tree longB tree long
B tree long
 
B+ Tree
B+ TreeB+ Tree
B+ Tree
 
B tree
B treeB tree
B tree
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
Indexing and-hashing
Indexing and-hashingIndexing and-hashing
Indexing and-hashing
 
B Trees
B TreesB Trees
B Trees
 
Best for b trees
Best for b treesBest for b trees
Best for b trees
 
Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashing
 
B tree
B treeB tree
B tree
 
b+ tree
b+ treeb+ tree
b+ tree
 

Similar to Red black trees presentation

redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxRAtna29
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structureVrushali Dhanokar
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementationUmang Gupta
 
AA trees (20PT25 and 20PT27 - ADS Presentation)
AA trees (20PT25 and 20PT27 - ADS Presentation)AA trees (20PT25 and 20PT27 - ADS Presentation)
AA trees (20PT25 and 20PT27 - ADS Presentation)Shree10271
 
lecture 14
lecture 14lecture 14
lecture 14sajinsc
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)amna izzat
 
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptUnit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptSheba41
 
Red Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, DeletionRed Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, Deletiona123007
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their propertiesKousalya M
 

Similar to Red black trees presentation (12)

6_1 (1).ppt
6_1 (1).ppt6_1 (1).ppt
6_1 (1).ppt
 
redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptx
 
Red black tree in data structure
Red black tree in data structureRed black tree in data structure
Red black tree in data structure
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementation
 
AA trees (20PT25 and 20PT27 - ADS Presentation)
AA trees (20PT25 and 20PT27 - ADS Presentation)AA trees (20PT25 and 20PT27 - ADS Presentation)
AA trees (20PT25 and 20PT27 - ADS Presentation)
 
lecture 14
lecture 14lecture 14
lecture 14
 
Lec14
Lec14Lec14
Lec14
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
 
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.pptUnit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
 
Red Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, DeletionRed Black Tree,Red black tree, Cases-insertion, Deletion
Red Black Tree,Red black tree, Cases-insertion, Deletion
 
Red-black trees
Red-black treesRed-black trees
Red-black trees
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their properties
 

More from Dexter Paul Gumahad

Glord's Brochure || Created by Me Using MS Word
Glord's Brochure || Created by Me Using MS WordGlord's Brochure || Created by Me Using MS Word
Glord's Brochure || Created by Me Using MS WordDexter Paul Gumahad
 
Lacason's Brochure || Designed by Me Using MS Word
Lacason's Brochure || Designed by Me Using MS WordLacason's Brochure || Designed by Me Using MS Word
Lacason's Brochure || Designed by Me Using MS WordDexter Paul Gumahad
 
Tulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
Tulisana's Brochure Presentation || Designed by Me Using MS PowerpointTulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
Tulisana's Brochure Presentation || Designed by Me Using MS PowerpointDexter Paul Gumahad
 
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PS
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PSTulisana's Brochure || Designed by Me Using MS Word & Adobe PS
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PSDexter Paul Gumahad
 
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PS
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PSValerie's Brochure || Designed by Me Using MS Word @ Adobe PS
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PSDexter Paul Gumahad
 
Bayobay's Programme || My Work - Simpliest
Bayobay's Programme || My Work - SimpliestBayobay's Programme || My Work - Simpliest
Bayobay's Programme || My Work - SimpliestDexter Paul Gumahad
 

More from Dexter Paul Gumahad (6)

Glord's Brochure || Created by Me Using MS Word
Glord's Brochure || Created by Me Using MS WordGlord's Brochure || Created by Me Using MS Word
Glord's Brochure || Created by Me Using MS Word
 
Lacason's Brochure || Designed by Me Using MS Word
Lacason's Brochure || Designed by Me Using MS WordLacason's Brochure || Designed by Me Using MS Word
Lacason's Brochure || Designed by Me Using MS Word
 
Tulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
Tulisana's Brochure Presentation || Designed by Me Using MS PowerpointTulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
Tulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
 
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PS
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PSTulisana's Brochure || Designed by Me Using MS Word & Adobe PS
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PS
 
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PS
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PSValerie's Brochure || Designed by Me Using MS Word @ Adobe PS
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PS
 
Bayobay's Programme || My Work - Simpliest
Bayobay's Programme || My Work - SimpliestBayobay's Programme || My Work - Simpliest
Bayobay's Programme || My Work - Simpliest
 

Recently uploaded

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 

Recently uploaded (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 

Red black trees presentation

  • 1. Red-Black Trees Niño Guerrero Dexter Paul Gumahad Rene Madera Reymart Pagente Data Structure || JRMSU Computer Science
  • 2. Red-Black Trees • A Red-Black tree is a binary search tree with these traits: – Every node is either red or black. – The root is always black. – If a node is red, its children must be black. – Every path from any node to a null must have the same number of black nodes. • Operations on Red-Black trees are O(log N). Data Structure || JRMSU Computer Science
  • 4. Red-Black Trees • Red-black trees can be thought of as binary tree representations of a 2-3-4 tree. • A 2-3-4 tree is a B-tree of degree 4. • This means each internal node has either 2, 3, or 4 children. • The next slide illustrates this. Data Structure || JRMSU Computer Science
  • 5. 2-3-4 tree c a b f d e Data Structure || JRMSU Computer Science g
  • 6. How the Trees Relate c c a f d e f a b d b g g e Each black node represents a node in the 2-3-4 tree. Each red node is in the same node with its black parent. This explains why every path has the same number of black nodes. Data Structure || JRMSU Computer Science
  • 8. Inserting into a Red-Black Tree • An inserted node is placed as in a binary search tree as a red node, unless it is the root. • If the parent of the new node is also red, called a “double red”, the tree will have to be adjusted, since a red child must have a black parent. Data Structure || JRMSU Computer Science
  • 9. Two Cases 1. a u w c b 2. a Inserting node z causes double red, and z’s parent has black sibling w. This occurs when a 4-node is malformed: must restructure. v z u c w b z v Inserting node z causes double red, and z’s parent has red sibling w. This occurs when a 4-node overflows: must recolor. Note: these are partial trees so not all Data Structure || JRMSU Computer subtrees are shown. of their Science
  • 10. Restructuring a c w c w a b a w c b b c b Double rotation w a Single rotation b The malformed 4-node is now a well-formed 4-node. a c Data Structure || JRMSU Computer Science Parent is black, children are red.
  • 11. Recoloring b b w d a w d a c c b w a b c w a d Note: since b is now red, this can cause a double red with b’s parent. If so, the two cases are considered again for Science its parent. Data Structure || JRMSU Computer b and c d
  • 12. Example e e e h h k 1. Insert e 2. Insert h h h e k e 3. Insert k, h has null (black) sibling h e k n 4. Restructure 5. Insert n, k has red sibling Data Structure || JRMSU Computer Science k n 6. Recolor (root left black)
  • 13. End Data Structure || JRMSU Computer Science