SlideShare a Scribd company logo
1 of 11
RED BLACK TREE
Red Black tree is self balancing binary search tree(BST),where every node follows
following rules.
•Every node has a color either Red or Black.
•Root of tree is always black.
•There are no two adjacent red nodes ( A Red node can not have a red parent or Red
child).
•If a node is Red , then both it’s children is Black.
•Every path from root to a Null node has same number of black nodes.
6/10/2017 Abhimanyu Mishra(CSE) JETGI 1
Example of Red Black Tree
6/10/2017 Abhimanyu Mishra(CSE) JETGI 2
8
4 17
219
N N
N N N N
•Perform standard BST insertion and make the colour of newly
inserted nodes as Red.
Let X be the newly inserted node.
•If X is root , change colour of X as Black.
•Do following if colour of X’s parent is not Black or X is not
root.
1. If X’s uncle is red.
Change colour of parent and uncle as Black.
Colour of grand parent as Red.
Insertion of Red Black Tree
6/10/2017 Abhimanyu Mishra(CSE) JETGI 3
5
3 8
6
8
6
5
3
6
83
5
2.If X’s uncle is Black .It contains four cases for X, X’s parent and grandparent .
6/10/2017 Abhimanyu Mishra(CSE) JETGI 4
i. Left left case
g
p u
x u
gx
p
ii. Left right case
g
p u
x
g
x u
p u
gp
x
ii. Right right case
g
p
u
xg
p
x
u
iv. Right left case
Deletion of Red Black Tree
It is fairly complex process. To understand deletion ,notation of double
black is used . When a black node is deleted and replaced by a black child
,the child is marked as double black.
Case 1: X’s sibling is Red.
Case 2: X’s sibling W is Black , and both of W’s children are Black.
Case 3: X’s sibling W is Black ,W’s left child is Red, and W’s right child
is Black.
Case 4: X’s sibling W is Black ,and W’s right child is Red.
6/10/2017 Abhimanyu Mishra(CSE) JETGI 5
g
u p
p
xu
g
x
u
pg
x
eEXdddasdExample of insertion
Insert 41
Insert 38
Insert 31
Insert 12
Insert 19
6/10/2017 Abhimanyu Mishra(CSE) JETGI 6
41
41
38
38
31
38
41
38
41
31
31
12
41
38
12
4131
4131
38 38
19
12 12
4119
31
Example of Deletion
Delete 87
Delete 71
6/10/2017 Abhimanyu Mishra(CSE) JETGI 7
47
71
93
82
8765
93
82
8765
71
47
47
93
82
82
87
93
65
71
41
Binomial Heap
• It is a data structure similar to binary heap but also supporting the operation of
merging two heaps .It is implemented by collection of binomial trees.
Structure of Binomial Heap
A binomial heap is implemented as a set of binomial trees that satisfy the binomial
heap properties:
• Each binomial tree in a heap obeys the minimum-heap property: the key of a node
is greater than or equal to the key of its parent.
• There can only be either one or zero binomial trees for each order, including zero
order.
• The first property ensures that the root of each binomial tree contains the smallest
key in the tree, which applies to the entire heap.
• The second property implies that a binomial heap with n nodes consists of at
most log n + 1 binomial trees. In fact, the number and orders of these trees are
uniquely determined by the number of nodes n: each binomial tree corresponds to
one digit in the binary representation of number n. For example number 13 is 1101
in binary, {display style 2^{3}+2^{2}+2^{0}}, and thus a binomial heap with 13
nodes will consist of three binomial trees of orders 3, 2, and 0 (see figure below).
6/10/2017 Abhimanyu Mishra(CSE) JETGI 8
6/10/2017 Abhimanyu Mishra(CSE) JETGI 9
Example of a binomial heap containing 13 nodes with distinct keys.
The heap consists of three binomial trees with orders 0, 2, and 3.Implementation.
•Insert
Inserting a new element to a heap can be done by simply creating a new
heap containing only this element and then merging it with the original heap.
Due to the merge, insert takes O(log n) time. However, across a series
of n consecutive insertions, insert has an amortized time of O(1) (i.e.
constant).
6/10/2017 Abhimanyu Mishra(CSE) JETGI 10
6/10/2017 Abhimanyu Mishra(CSE) JETGI 11
• Delete
To delete an element from the heap, decrease its key to negative infinity (that is, some
value lower than any element in the heap) and then delete the minimum in the
heap.

More Related Content

What's hot

Red black tree
Red black treeRed black tree
Red black treeuos lahore
 
Exponent exercises
Exponent exercisesExponent exercises
Exponent exercisesingarcia
 
Mathematics: Addition Then Subtraction
Mathematics: Addition Then  Subtraction Mathematics: Addition Then  Subtraction
Mathematics: Addition Then Subtraction LorenKnights
 
Day 8 examples u5w14
Day 8 examples u5w14Day 8 examples u5w14
Day 8 examples u5w14jchartiersjsd
 
lossless data compression and decompression using simple byte coding
lossless data compression and decompression using simple byte codinglossless data compression and decompression using simple byte coding
lossless data compression and decompression using simple byte codingHarshini Thota
 
Str8ts Weekly Extreme #39 - Solution
Str8ts Weekly Extreme #39 - SolutionStr8ts Weekly Extreme #39 - Solution
Str8ts Weekly Extreme #39 - SolutionSlowThinker
 
Prime Factorization (Math 4)
Prime Factorization  (Math 4)Prime Factorization  (Math 4)
Prime Factorization (Math 4)menchreo
 
Unit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi KathuriaUnit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi Kathuriakulachihansraj
 
unit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriaunit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriakulachihansraj
 
Algebraicexpressions1.2
Algebraicexpressions1.2Algebraicexpressions1.2
Algebraicexpressions1.2gheovani
 
Abby's project 1
Abby's project 1Abby's project 1
Abby's project 1daisyrock
 

What's hot (20)

10 Red-Black Trees
10 Red-Black Trees10 Red-Black Trees
10 Red-Black Trees
 
Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)Balanced Tree(AVL Tree,Red Black Tree)
Balanced Tree(AVL Tree,Red Black Tree)
 
16 rbtrees
16 rbtrees16 rbtrees
16 rbtrees
 
Red black tree
Red black treeRed black tree
Red black tree
 
Red black 1
Red black 1Red black 1
Red black 1
 
Exponent exercises
Exponent exercisesExponent exercises
Exponent exercises
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Red black trees
Red black treesRed black trees
Red black trees
 
Mathematics: Addition Then Subtraction
Mathematics: Addition Then  Subtraction Mathematics: Addition Then  Subtraction
Mathematics: Addition Then Subtraction
 
Day 8 examples u5w14
Day 8 examples u5w14Day 8 examples u5w14
Day 8 examples u5w14
 
New day 7 examples
New day 7 examplesNew day 7 examples
New day 7 examples
 
lossless data compression and decompression using simple byte coding
lossless data compression and decompression using simple byte codinglossless data compression and decompression using simple byte coding
lossless data compression and decompression using simple byte coding
 
Str8ts Weekly Extreme #39 - Solution
Str8ts Weekly Extreme #39 - SolutionStr8ts Weekly Extreme #39 - Solution
Str8ts Weekly Extreme #39 - Solution
 
Prime Factorization (Math 4)
Prime Factorization  (Math 4)Prime Factorization  (Math 4)
Prime Factorization (Math 4)
 
B+ tree
B+ treeB+ tree
B+ tree
 
Unit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi KathuriaUnit cube Activity 1 by Ms. Rashmi Kathuria
Unit cube Activity 1 by Ms. Rashmi Kathuria
 
unit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuriaunit cube Activity4 by Ms. Rashmi Kathuria
unit cube Activity4 by Ms. Rashmi Kathuria
 
Algebraicexpressions1.2
Algebraicexpressions1.2Algebraicexpressions1.2
Algebraicexpressions1.2
 
The Derivative of e^x and lnx
The Derivative of e^x and lnxThe Derivative of e^x and lnx
The Derivative of e^x and lnx
 
Abby's project 1
Abby's project 1Abby's project 1
Abby's project 1
 

Similar to Daa unit 2

Balance tree. Short overview
Balance tree. Short overviewBalance tree. Short overview
Balance tree. Short overviewElifTech
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structureAnusruti Mitra
 
RED BLACK TREE ADSA UNIT 1 ROTAITON RED B
RED BLACK TREE ADSA UNIT 1 ROTAITON RED BRED BLACK TREE ADSA UNIT 1 ROTAITON RED B
RED BLACK TREE ADSA UNIT 1 ROTAITON RED BSalini P
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.pptplagcheck
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
trees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptxtrees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptxTanvirAhmed166122
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementationUmang Gupta
 
lecture 14
lecture 14lecture 14
lecture 14sajinsc
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAdityaK92
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 

Similar to Daa unit 2 (14)

Balance tree. Short overview
Balance tree. Short overviewBalance tree. Short overview
Balance tree. Short overview
 
Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
unit06-3-Trees.pdf
unit06-3-Trees.pdfunit06-3-Trees.pdf
unit06-3-Trees.pdf
 
RED BLACK TREE ADSA UNIT 1 ROTAITON RED B
RED BLACK TREE ADSA UNIT 1 ROTAITON RED BRED BLACK TREE ADSA UNIT 1 ROTAITON RED B
RED BLACK TREE ADSA UNIT 1 ROTAITON RED B
 
15-btrees.ppt
15-btrees.ppt15-btrees.ppt
15-btrees.ppt
 
Red black tree
Red black treeRed black tree
Red black tree
 
Cse 225 rbt_red_black_tree
Cse 225 rbt_red_black_treeCse 225 rbt_red_black_tree
Cse 225 rbt_red_black_tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Review session2
Review session2Review session2
Review session2
 
trees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptxtrees-and-graphs_computer_science_for_student.pptx
trees-and-graphs_computer_science_for_student.pptx
 
Advanced data structures and implementation
Advanced data structures and implementationAdvanced data structures and implementation
Advanced data structures and implementation
 
lecture 14
lecture 14lecture 14
lecture 14
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Red black tree
Red black treeRed black tree
Red black tree
 

More from Abhimanyu Mishra

More from Abhimanyu Mishra (20)

Cd unit i
Cd unit iCd unit i
Cd unit i
 
Presentation1(JIT gnomio)
Presentation1(JIT gnomio)Presentation1(JIT gnomio)
Presentation1(JIT gnomio)
 
Sta unit 5(abimanyu)
Sta unit 5(abimanyu)Sta unit 5(abimanyu)
Sta unit 5(abimanyu)
 
Sta unit 3(abimanyu)
Sta unit 3(abimanyu)Sta unit 3(abimanyu)
Sta unit 3(abimanyu)
 
Sta unit 4(abimanyu)
Sta unit 4(abimanyu)Sta unit 4(abimanyu)
Sta unit 4(abimanyu)
 
Sta unit 3(abimanyu)
Sta unit 3(abimanyu)Sta unit 3(abimanyu)
Sta unit 3(abimanyu)
 
Sta unit 2(abimanyu)
Sta unit 2(abimanyu)Sta unit 2(abimanyu)
Sta unit 2(abimanyu)
 
Unit1
Unit1Unit1
Unit1
 
Daa unit 5
Daa unit 5Daa unit 5
Daa unit 5
 
Daa unit 4
Daa unit 4Daa unit 4
Daa unit 4
 
Daa unit 3
Daa unit 3Daa unit 3
Daa unit 3
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Software Engineering unit 5
Software Engineering unit 5Software Engineering unit 5
Software Engineering unit 5
 
Software Engineering unit 4
Software Engineering unit 4Software Engineering unit 4
Software Engineering unit 4
 
Software Engineering unit 3
Software Engineering unit 3Software Engineering unit 3
Software Engineering unit 3
 
Software Engineering unit 2
Software Engineering unit 2Software Engineering unit 2
Software Engineering unit 2
 
Software Engineering Unit 1
Software Engineering Unit 1Software Engineering Unit 1
Software Engineering Unit 1
 
Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5
 
Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4Theory of automata and formal languages Unit 4
Theory of automata and formal languages Unit 4
 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3
 

Recently uploaded

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Recently uploaded (20)

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

Daa unit 2

  • 1. RED BLACK TREE Red Black tree is self balancing binary search tree(BST),where every node follows following rules. •Every node has a color either Red or Black. •Root of tree is always black. •There are no two adjacent red nodes ( A Red node can not have a red parent or Red child). •If a node is Red , then both it’s children is Black. •Every path from root to a Null node has same number of black nodes. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 1
  • 2. Example of Red Black Tree 6/10/2017 Abhimanyu Mishra(CSE) JETGI 2 8 4 17 219 N N N N N N
  • 3. •Perform standard BST insertion and make the colour of newly inserted nodes as Red. Let X be the newly inserted node. •If X is root , change colour of X as Black. •Do following if colour of X’s parent is not Black or X is not root. 1. If X’s uncle is red. Change colour of parent and uncle as Black. Colour of grand parent as Red. Insertion of Red Black Tree 6/10/2017 Abhimanyu Mishra(CSE) JETGI 3 5 3 8 6 8 6 5 3 6 83 5
  • 4. 2.If X’s uncle is Black .It contains four cases for X, X’s parent and grandparent . 6/10/2017 Abhimanyu Mishra(CSE) JETGI 4 i. Left left case g p u x u gx p ii. Left right case g p u x g x u p u gp x ii. Right right case g p u xg p x u
  • 5. iv. Right left case Deletion of Red Black Tree It is fairly complex process. To understand deletion ,notation of double black is used . When a black node is deleted and replaced by a black child ,the child is marked as double black. Case 1: X’s sibling is Red. Case 2: X’s sibling W is Black , and both of W’s children are Black. Case 3: X’s sibling W is Black ,W’s left child is Red, and W’s right child is Black. Case 4: X’s sibling W is Black ,and W’s right child is Red. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 5 g u p p xu g x u pg x
  • 6. eEXdddasdExample of insertion Insert 41 Insert 38 Insert 31 Insert 12 Insert 19 6/10/2017 Abhimanyu Mishra(CSE) JETGI 6 41 41 38 38 31 38 41 38 41 31 31 12 41 38 12 4131 4131 38 38 19 12 12 4119 31
  • 7. Example of Deletion Delete 87 Delete 71 6/10/2017 Abhimanyu Mishra(CSE) JETGI 7 47 71 93 82 8765 93 82 8765 71 47 47 93 82 82 87 93 65 71 41
  • 8. Binomial Heap • It is a data structure similar to binary heap but also supporting the operation of merging two heaps .It is implemented by collection of binomial trees. Structure of Binomial Heap A binomial heap is implemented as a set of binomial trees that satisfy the binomial heap properties: • Each binomial tree in a heap obeys the minimum-heap property: the key of a node is greater than or equal to the key of its parent. • There can only be either one or zero binomial trees for each order, including zero order. • The first property ensures that the root of each binomial tree contains the smallest key in the tree, which applies to the entire heap. • The second property implies that a binomial heap with n nodes consists of at most log n + 1 binomial trees. In fact, the number and orders of these trees are uniquely determined by the number of nodes n: each binomial tree corresponds to one digit in the binary representation of number n. For example number 13 is 1101 in binary, {display style 2^{3}+2^{2}+2^{0}}, and thus a binomial heap with 13 nodes will consist of three binomial trees of orders 3, 2, and 0 (see figure below). 6/10/2017 Abhimanyu Mishra(CSE) JETGI 8
  • 9. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 9 Example of a binomial heap containing 13 nodes with distinct keys. The heap consists of three binomial trees with orders 0, 2, and 3.Implementation. •Insert Inserting a new element to a heap can be done by simply creating a new heap containing only this element and then merging it with the original heap. Due to the merge, insert takes O(log n) time. However, across a series of n consecutive insertions, insert has an amortized time of O(1) (i.e. constant).
  • 11. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 11 • Delete To delete an element from the heap, decrease its key to negative infinity (that is, some value lower than any element in the heap) and then delete the minimum in the heap.