SlideShare a Scribd company logo
1 of 14
Data Structure & Files
Unit 5: Advance Tree
Red Black Binary Tree
Why & What is mean by Red-Black Tree?
• Red-Black Tree is a self-balancing Binary Search Tree (BST).
• Every node is colored with Red or Black.
Why Red Black Tree?
• Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h
is the height of the BST. The cost of these operations is high.
• The height of a Red-Black tree is always O(Log n) where n is the number of nodes in the tree.
Properties of Red Black Tree
1. Every node has a color either Red or Black.
2. Root of tree is always Black.
3. Leaf node or NULL node always Red.
4. Children's of Red Node are Black, Parent of Red Node is Black.
5. Every path from a node (including root) to any of its descendant NULL node has the same
number of Black nodes.
Every Red Black Tree is a binary search tree but every Binary Search Tree need not be Red
Black tree.
Insertion in Red-Black Tree: (Conditions)
1. Tree is empty – Add root node with color Black.
2. Tree is not empty – Add new node with color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL then perform suitable Rotation & Recolor.
b. If parent of sibling is Red then Recolor and also check if parents parent of newnode
is not root node then Recolor it and Check it
Rotation Means?
Rotations: L-Left & R-Right
• It occurs on only newnode and There Parent’s Node.
1. LR Relationship – 1. Left Rotation 2. Right Rotation
2. RL Relationship – 1. Right Rotation 2. Left Rotation
It occurs on newnode , there Parent’s Node and also there Parent’s node.
1. LL Relationship – 1. Right Rotation
2. RR Relationship – 1. Left Rotation
Insertion Examples (Add data according BST property)
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with color
Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL then
perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor and
also check if parents parent of newnode is not root
node then Recolor it and Check it
Create Red-Black Tree for
8,18,5,15,17,25,40 ,80.
Continue..
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check
the color of parent’s siblings of new
node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check
the color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Continue..!
1. Tree is empty – Add root node with color
Black.
2. Tree is not empty – Add new node with
color Red.
3. If parent of newnode is Black then exit.
4. If parent of newnode is Red then check the
color of parent’s siblings of new node-
a. If parent of sibling is Black or NULL
then perform suitable rotation & Recolor.
b. If parent of sibling is Red then Recolor
and also check if parents parent of newnode is
not root node then Recolor it and Check it
Applications of Red-Black Tree
1. Linux Kernal, For process scheduler or for keeping track of virtual
memory segmentation segments for a process.
2. Used in map, multimap, multiset from C++ STL and java.util.TreeMap ,
java.util.TreeSet from Java.
3. They are use in K-mean clustering algorithm for reducing time complexity.
4. MySQL uses Red-Black Trees for indexes on tables.
5. Fast searching can be occur.
Important Questions
1. Write a short note on Red-Black Tree? 6M
2. Explain Red-Black Tree in detail. 6M
3. Write properties of Red-Black Tree. 3M
4. Construct Red-Black Tree for given numbers:
10,18,7,15,16,20,25,40,60,21,70. 8M
Thank You…!

More Related Content

Similar to redblacktreeindatastructure-200409083949.pptx

Similar to redblacktreeindatastructure-200409083949.pptx (20)

Red black trees1109
Red black trees1109Red black trees1109
Red black trees1109
 
Red black trees presentation
Red black trees presentationRed black trees presentation
Red black trees presentation
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their properties
 
Lec14
Lec14Lec14
Lec14
 
Red black trees
Red black treesRed black trees
Red black trees
 
Red black tree
Red black treeRed black tree
Red black tree
 
LEC 5-DS ALGO(updated).pdf
LEC 5-DS  ALGO(updated).pdfLEC 5-DS  ALGO(updated).pdf
LEC 5-DS ALGO(updated).pdf
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Binary tree
Binary treeBinary tree
Binary tree
 
Trees
TreesTrees
Trees
 
Tree
TreeTree
Tree
 
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdfanastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
anastasio-red-black-trees-1-1-091222204455-phpapp02.pdf
 
Red black trees
Red black treesRed black trees
Red black trees
 
Cse 225 rbt_red_black_tree
Cse 225 rbt_red_black_treeCse 225 rbt_red_black_tree
Cse 225 rbt_red_black_tree
 
Red blacktrees
Red blacktreesRed blacktrees
Red blacktrees
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Red black tree
Red black treeRed black tree
Red black tree
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Unit 5 Tree.pptx
Unit 5 Tree.pptxUnit 5 Tree.pptx
Unit 5 Tree.pptx
 

More from RAtna29

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbRAtna29
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt tttttttttttttttttttttttttttttRAtna29
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzRAtna29
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmRAtna29
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNRAtna29
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyRAtna29
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhRAtna29
 
btree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggbtree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggRAtna29
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
avltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examavltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examRAtna29
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuRAtna29
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmRAtna29
 

More from RAtna29 (15)

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
btree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggbtree.ppt ggggggggggggggggggggggggggggggg
btree.ppt ggggggggggggggggggggggggggggggg
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
avltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university examavltrees.ppt unit 4 ppts for the university exam
avltrees.ppt unit 4 ppts for the university exam
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmm
 

Recently uploaded

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 

redblacktreeindatastructure-200409083949.pptx

  • 1. Data Structure & Files Unit 5: Advance Tree Red Black Binary Tree
  • 2. Why & What is mean by Red-Black Tree? • Red-Black Tree is a self-balancing Binary Search Tree (BST). • Every node is colored with Red or Black. Why Red Black Tree? • Most of the BST operations (e.g., search, max, min, insert, delete.. etc) take O(h) time where h is the height of the BST. The cost of these operations is high. • The height of a Red-Black tree is always O(Log n) where n is the number of nodes in the tree.
  • 3. Properties of Red Black Tree 1. Every node has a color either Red or Black. 2. Root of tree is always Black. 3. Leaf node or NULL node always Red. 4. Children's of Red Node are Black, Parent of Red Node is Black. 5. Every path from a node (including root) to any of its descendant NULL node has the same number of Black nodes. Every Red Black Tree is a binary search tree but every Binary Search Tree need not be Red Black tree.
  • 4. Insertion in Red-Black Tree: (Conditions) 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable Rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 5. Rotation Means? Rotations: L-Left & R-Right • It occurs on only newnode and There Parent’s Node. 1. LR Relationship – 1. Left Rotation 2. Right Rotation 2. RL Relationship – 1. Right Rotation 2. Left Rotation It occurs on newnode , there Parent’s Node and also there Parent’s node. 1. LL Relationship – 1. Right Rotation 2. RR Relationship – 1. Left Rotation
  • 6. Insertion Examples (Add data according BST property) 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it Create Red-Black Tree for 8,18,5,15,17,25,40 ,80.
  • 7. Continue.. 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 8. Continue.. 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 9. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 10. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 11. Continue..! 1. Tree is empty – Add root node with color Black. 2. Tree is not empty – Add new node with color Red. 3. If parent of newnode is Black then exit. 4. If parent of newnode is Red then check the color of parent’s siblings of new node- a. If parent of sibling is Black or NULL then perform suitable rotation & Recolor. b. If parent of sibling is Red then Recolor and also check if parents parent of newnode is not root node then Recolor it and Check it
  • 12. Applications of Red-Black Tree 1. Linux Kernal, For process scheduler or for keeping track of virtual memory segmentation segments for a process. 2. Used in map, multimap, multiset from C++ STL and java.util.TreeMap , java.util.TreeSet from Java. 3. They are use in K-mean clustering algorithm for reducing time complexity. 4. MySQL uses Red-Black Trees for indexes on tables. 5. Fast searching can be occur.
  • 13. Important Questions 1. Write a short note on Red-Black Tree? 6M 2. Explain Red-Black Tree in detail. 6M 3. Write properties of Red-Black Tree. 3M 4. Construct Red-Black Tree for given numbers: 10,18,7,15,16,20,25,40,60,21,70. 8M