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

PPTX
01 Knapsack using Dynamic Programming
PPTX
Lecture optimal binary search tree
PPT
B trees in Data Structure
PPTX
Binary Search Tree in Data Structure
PDF
All pairs shortest path algorithm
PPTX
Data structure tries
PPT
Minimum spanning tree
PPT
Leftist heap
01 Knapsack using Dynamic Programming
Lecture optimal binary search tree
B trees in Data Structure
Binary Search Tree in Data Structure
All pairs shortest path algorithm
Data structure tries
Minimum spanning tree
Leftist heap

What's hot (20)

PDF
Red black tree
PPTX
Red black trees
PPTX
Trees (data structure)
PPT
File organisation
PPTX
Graph coloring using backtracking
PDF
Red black tree
PPS
Single linked list
PPTX
Prims and kruskal algorithms
PPTX
Breadth First Search & Depth First Search
PPT
12. Indexing and Hashing in DBMS
PPTX
Travelling salesman dynamic programming
PPTX
Topological Sorting
PPTX
PDF
Recurrence relation solutions
PPT
B trees and_b__trees
PPTX
trigger dbms
PDF
PPTX
convex hull
PPTX
Bellman ford algorithm
PPTX
Asymptotic Notation and Data Structures
Red black tree
Red black trees
Trees (data structure)
File organisation
Graph coloring using backtracking
Red black tree
Single linked list
Prims and kruskal algorithms
Breadth First Search & Depth First Search
12. Indexing and Hashing in DBMS
Travelling salesman dynamic programming
Topological Sorting
Recurrence relation solutions
B trees and_b__trees
trigger dbms
convex hull
Bellman ford algorithm
Asymptotic Notation and Data Structures
Ad

Viewers also liked (20)

PPT
Red black tree
PPT
Red Black Trees
PDF
Red Black Trees
PDF
10 Red-Black Trees
PPTX
Red black trees
PDF
Algebra 1 2.8 Algebraic Proof
PPTX
Insertion in RED BLACK TREE
PPTX
Struktur data 06 (red black tree)
PPTX
Splay trees by NIKHIL ARORA (www.internetnotes.in)
PPTX
Logic gates with laws
PPTX
Red black trees1109
PPTX
B tree long
PPTX
B+ Tree
PPT
B tree
PDF
Fundamentals of data structures ellis horowitz & sartaj sahni
PDF
Indexing and-hashing
PPT
PPT
Best for b trees
PPT
Indexing and hashing
Red black tree
Red Black Trees
Red Black Trees
10 Red-Black Trees
Red black trees
Algebra 1 2.8 Algebraic Proof
Insertion in RED BLACK TREE
Struktur data 06 (red black tree)
Splay trees by NIKHIL ARORA (www.internetnotes.in)
Logic gates with laws
Red black trees1109
B tree long
B+ Tree
B tree
Fundamentals of data structures ellis horowitz & sartaj sahni
Indexing and-hashing
Best for b trees
Indexing and hashing
Ad

Similar to Red black trees presentation (20)

PPT
RedBlackTrees_2.pptmmmmmmmmmmmmmmmmmmmmmmmmmm
PPT
RedBlackTrees_2.pptNNNNNNNNNNNNNNNNNNNNNN
PPTX
redblacktreeindatastructure-200409083949.pptx
PPTX
Kishan Kaushik - Red Black Tree Presentation
PPTX
Red black tree in data structure
PPT
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
PPT
lecture 14
PPTX
Red black tree
PDF
Red black trees
PPTX
Red Black Tree,Red black tree, Cases-insertion, Deletion
PPTX
Red black tree
PPTX
Red-black-tree presentation in Algorithm
PDF
Red-Black Tree Presentation By Mobin Nesari.pdf
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
PPTX
Balanced Tree(AVL Tree,Red Black Tree)
PPTX
Data structure
PPT
Advanced data structures and implementation
PPTX
Red black tree insertion
PPT
16 rbtrees
RedBlackTrees_2.pptmmmmmmmmmmmmmmmmmmmmmmmmmm
RedBlackTrees_2.pptNNNNNNNNNNNNNNNNNNNNNN
redblacktreeindatastructure-200409083949.pptx
Kishan Kaushik - Red Black Tree Presentation
Red black tree in data structure
Unit 2 ADvanced Data Sturctures and Algorithms Red-black_trees.ppt
lecture 14
Red black tree
Red black trees
Red Black Tree,Red black tree, Cases-insertion, Deletion
Red black tree
Red-black-tree presentation in Algorithm
Red-Black Tree Presentation By Mobin Nesari.pdf
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)
Data structure
Advanced data structures and implementation
Red black tree insertion
16 rbtrees

More from Dexter Paul Gumahad (6)

DOCX
Glord's Brochure || Created by Me Using MS Word
DOCX
Lacason's Brochure || Designed by Me Using MS Word
PPTX
Tulisana's Brochure Presentation || Designed by Me Using MS Powerpoint
DOCX
Tulisana's Brochure || Designed by Me Using MS Word & Adobe PS
DOCX
Valerie's Brochure || Designed by Me Using MS Word @ Adobe PS
DOCX
Bayobay's Programme || My Work - Simpliest
Glord's Brochure || Created 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 || 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

Recently uploaded (20)

PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
observCloud-Native Containerability and monitoring.pptx
PPT
Geologic Time for studying geology for geologist
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Modernising the Digital Integration Hub
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
Developing a website for English-speaking practice to English as a foreign la...
Enhancing emotion recognition model for a student engagement use case through...
observCloud-Native Containerability and monitoring.pptx
Geologic Time for studying geology for geologist
WOOl fibre morphology and structure.pdf for textiles
A review of recent deep learning applications in wood surface defect identifi...
A contest of sentiment analysis: k-nearest neighbor versus neural network
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
Getting Started with Data Integration: FME Form 101
Hindi spoken digit analysis for native and non-native speakers
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Modernising the Digital Integration Hub
Final SEM Unit 1 for mit wpu at pune .pptx
A novel scalable deep ensemble learning framework for big data classification...
sustainability-14-14877-v2.pddhzftheheeeee
O2C Customer Invoices to Receipt V15A.pptx
Benefits of Physical activity for teenagers.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions

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