Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago