0% found this document useful (0 votes)
42 views9 pages

Red - Black - Tree (1) 1

It is description about red black tree in c language

Uploaded by

rushitha766
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views9 pages

Red - Black - Tree (1) 1

It is description about red black tree in c language

Uploaded by

rushitha766
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Red Black Tree

K.SOUMYA REDDY
23H51A66Y5
Introduction to Red Black Tree
Red Black Tree is a self-balancing binary
search tree that maintains balance during
insertions and deletions.

Red Black Tree is widely used in computer


science for its efficient search, insertion, and
deletion operations.

1
Rules for Red Black Tree
Rule 1: Every node is either red or black.
Rule 2: The root node of the tree is always black.
Rule 3: Red nodes have black children.

Rule 4:Every leaf(NULL NODE) must be coloured BLACK .

3
Rules for Red Black Tree
Rule 5: Every path from a node to its descendant NULL nodes has the
same number of black nodes.
Rule 6: Red nodes cannot have red children.

4
Insertion in Red Black Tree
1. if tree is empty ,create a newnode node as root
node with colour black.if tree is not empty,create
a newnode as leafnode with red colour.
2.if parent of newnode is black then exit.
Then if parent of newnode is red ,then check the
colour of parents siblings of newnode .

(a).if colour is black &NULL then do suitable rotation


&recolour.
(b).if colour is red then recolour &also check if parents
parent of newnode is not root node then recolour it
& rech eck .

5
SEARCHING:-
Search Steps:-

• Start at the Root: Begin the search at the root node.

• Traverse the Tree:


• If the target value is equal to the current node’s value, the node is found.
• If the target value is less than the current node’s value, move to the left child.
• If the target value is greater than the current node’s value, move to the right child.

• Repeat: Continue this process until the target value is found or a NIL node is reached

(indicating the value is not present in the tree).

6
Advantages of Red Black Tree
Red Black Tree offers guaranteed logarithmic
time complexity of for search, insert, and delete
operations.
Red blacktrees are self-balancing.

It provides a balanced tree structure, leading to


efficient performance and versatility.
This mechanism helps in simple&easy to
understand.

7
Applications of Red Black Tree
Red Black Tree is commonly used in the
implementation of language compilers, symbol
tables, and databases.
It is also used in data structures like TreeMap in
Java and set data structures in C++.
Red black trees are used in the implementation
of game engines

9
THANK YOU

10

You might also like