Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Among other things, a binary search tree can be used for sorting data elements. This project is to randomly generate a sequence of integer numbers, insert the first 20 distinct numbers into a binary search tree, and finally produce an in-order listing of the tree. You are provided with the declarations and two functions for binary search trees (see the appended). One of the functions is Insert that adds a new element to a binary search tree. And the other is lookup which checks if a given element is already in a binary search tree. In this project, you need to define a print function that prints tree elements in in-order as well as a count function that counts and returns the number of tree nodes in a binary search tree. In addition you need to complete the main function. You may use the built-in random number function to generate new elements for inserting as shown below:

srand(time(NULL)); /* do it at the beginning of main function */
newElem = rand() % 100; /* generate a new element one at a time */
Then you can check for each new element if it is already there using the lookup function and if there are enough elements in the tree using the count function before doing insert. Finally, use the print function to show the result.
/* declarations and function definitions for binary search trees */
#include
#include
#include
#define TRUE 1
#define FALSE 0
typedef int BOOLEAN;
typedef int ETYPE;
typedef struct NODE *TREE;
struct NODE {
ETYPE element;
TREE leftChild, rightChild;
};
TREE insert(ETYPE x, TREE T)
{
if (T == NULL) {
T = (TREE) malloc(sizeof(struct NODE));
T->element = x;
T->leftChild = NULL;
T->rightChild = NULL;
}
else if (x < T->element)
T->leftChild = insert(x, T->leftChild);
else if (x > T->element)
T->rightChild = insert(x, T->rightChild);
return T;
}
BOOLEAN lookup(ETYPE x, TREE T)
{
if (T == NULL)
return FALSE;
else if (x == T->element)
return TRUE;
else if (x < T->element)
return lookup(x, T->leftChild);
else /* x must be > T->element */
return lookup(x, T->rightChild);
}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91619688
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Question an agile-focused mind-set in project

Question: "An Agile-focused Mind-set in Project Management" • Read the following two (2) articles: "The Scrum Guide," located here and "Core Scrum," located here. Contrast the role of a Scrum Master and the role of a pro ...

How do you apply the five components of the information

How do you apply the five components of the information systems to an information systems application like "online bill pay" system offered by many banks.

What steps are required in determining the big-oh notation

What steps are required in determining the Big-Oh notation for the algorithm when sorting an array of integers 5 7 4 9 8 5 6 3 and showing the contents each time a selection sort changes it while sorting the array into a ...

Determine the number of moles of oleic acid in the

Determine the number of moles of oleic acid in the monolayer. Assume the nubmer of grams of oleic acid in the monolayer is  7.12×10 -6  g MW for oleic acid is 282 g/mol.

Question suppose a destination computer receives several

Question : Suppose a destination computer receives several packets from a source. How can it be sure that the fragments belonging to a datagram are not mixed with the fragments belonging to another datagram?

Starting out with cpp 8th edition pg 449 7 with

Starting out with Cpp 8th edition Pg 449 #7 WITH MODIFICATIONS! Write a program that asks the user for a file name, and then ask the user for up to 100 input values. Write the user input values to the file. Then read the ...

Answer the following question take a cube graph q3 and add

Answer the following Question : Take a cube graph Q3 and add both face diagonals to one of the cube faces. The resulting graph is not planar, so by Kuratowski's theorem it contains a subdivision of K5 or of K3,3. Draw th ...

Questionthe stable matching problem as discussed in the

Question The Stable Matching Problem, as discussed in the text, assumes that all men and women have a fully ordered list of preferences. In this problem we will consider a version of the problem in which men and women ca ...

Sectools - top 125 network security toolssnort websitenmap

SecTools - Top 125 Network Security Tools SNORT website Nmap website Lynx website (for a text browser) Wget website Teleport Pro website Research one of the tools listed in the chapter or linked above. Discuss its releva ...

Please help me find out how to calculate stock pricewhat is

Please help me find out how to calculate stock price. "What is the price of Company A's stock.We know company A pay dividend twice a year. And its beta=1.5 Government bond's Coupon is 8.8 and Yield is 5%(which one you sh ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As