Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program must be in programming language C and must use the skeleton code. It is provided underneath the question and can just be copied

This program must be in programming language C and must use the skeleton code. It is provided underneath the question and can just be copied and pasted and just need to add the missing code. thanks for the help.

image text in transcribed

#include  #include  typedef struct NodeT { int iInfo; struct NodeT *pLeft; struct NodeT *pRight; }NodeT; void drawTree(NodeT *pRoot, int level); int main() { return 0; } /* This draws a given tree. The first parameter is the root of the tree. * The second parameter will always be 0 when you call it in your code. * The tree is drawn with the root on the left side of the screen and it decends toward the right side of the screen. * You can use it to check that your code correctly generates small trees. * (You can reduce the number of nodes you add to the tree to about 10 do your testing) * Example 5 element tree with 450 as the root (570, 279, and 195 are the leaves): * * 570 * 450 * 279 * 211 * 195 */ void drawTree(NodeT *pRoot, int level){ int i; /* base case: there is nothing left to print */ if (pRoot == NULL) return; /* Print right subtree first */ drawTree( pRoot->pRight, level + 1 ); /* Print current next */ /* tab over level times to set the depth to print the iInfo at */ for( i = 0; i iInfo); /* Finally print left subtree */ drawTree( pRoot->pLeft, level + 1 ); } 

Write a C program to perform the following experiment Generate 100 random numbers. As each number is generated, insert it into an initially empty binary search tree. When all 100 numbers have been inserted, print the level of the leaf with the largest level and the level of the leaf with the smallest level. Repeat this process 50 times. Print out a table with a count of how many of the 50 runs resulted in a difference between the maximum and minimum leaf level of 0, 1, 2, 3, and so on. Implement your binary tree using dynamically allocated nodes, not an array. Remember that each of your 50 repetitions needs to print the largest and smallest leaf levels. At the end of all 50 runs, your program will print a summary of level differences and the # of runs. Here an example of the output format Level Difference #Runs 0 Use the following function to generate a random int from 1 to 1000 for each node you insert into your binary search tree: int generateRandom) return rand() % 1000 + 1; Continued on the back You should initialize the random number generator with the following line in your main function srand(time (NULL); Note: to use the time) function, you need to include the header file at the top of your C source file

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions