Question: Please give the solution in C language only and attach the output screenshot QA23.8 A Red-Black tree is a self-balancing binary search tree where every

Please give the solution in C language only and attach the output screenshot

QA23.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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!