Question
Please give the solution in C language only and Please attach the output screenshot and dont post wong solution 2300.8 A Red-Black tree is a
Please give the solution in C language only and Please attach the output screenshot and dont post wong solution
2300.8 A Red-Black tree is a self-balancing binary search tree where every node obeys the following rules.
(a) Every node is either red or black
(b) The root is always black
(c) There are no two adjacent red nodes (A red node cannot have a red parent or red child)
(d) All paths from a node to descendant nodes contain the same number of black nodes
Write a program to create a Red Black Tree from the given input. Your program should include
the following function
InsertRedBlack(struct node* root, key) : Inserts a new node with the key into the tree
and prints parenthesized representation (with corresponding colors) of the created red-black
tree.
Input Format:
Each line of the input contains a positive integer key or a character t. If the input is
a positive integer then Call function InsertRedBlack(root, key). If t is encountered,
terminate the program.
Output Format:
For each line of the input, the corresponding line of the output should contain the Parenthesis Representation (key value followed by color) of the current tree.
Sample Input:
25
18
50
80
12
100
34
t
Sample Output:
( 25 B ( ) ( ) )
( 25 B ( 18 R ( ) ( ) ) ( ) )
( 25 B ( 18 R ( ) ( ) ) ( 50 R ( ) ( ) ) )
( 25 B ( 18 B ( ) ( ) ) ( 50 B ( ) ( 80 R ( ) ( ) ) ) )
( 25 B ( 18 B ( 12 R ( ) ( ) ) ( ) ) ( 50 B ( ) ( 80 R ( ) ( ) ) ) )
( 25 B ( 18 B ( 12 R ( ) ( ) ) ( ) ) ( 80 B ( 50 R ( ) ( ) ) ( 100 R ( ) ( ) ) ) )
( 25 B ( 18 B ( 12 R ( ) ( ) ) ( ) ) ( 80 R ( 50 B ( 34 R ( ) ( ) ) ( ) ) ( 100 B ( ) ( ) ) ) )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started