Question: Project 8: Binary Search Tree: Average Number of Comparisons for a Successful Search Due: November 10, 1 PM (submission through Canvas) You are given the
Project 8: Binary Search Tree: Average Number of Comparisons for a Successful Search Due: November 10, 1 PM (submission through Canvas) You are given the following code: (1) Code to construct a binary search tree using a sorted randomly generated array of integers (2) Code to determine the depth (level numbers) of the vertices in a binary tree Add a member function assignLevelNumbers() to the Binary Search Tree class to determine the level numbers of the vertices in a binary search tree (start Breadth First Search with the rootNodelD, which is considered to be at level 0) Add a member function getLevelNumber(int nodeid) in the Binary Search Tree class that in turn calls the getLevelNum) function on the BST node object corresponding to the 'nodeid' and returns the level number of node identified by its id. In the main function, first call the assignLevelNumbers) function on the object of class Binary Search Tree before determining the number of c omparisons for successful search. Successful search: During the lecture, we saw that the number of comparisons for the successful search of a key in a binary search tree (BST) is one more than the level number of the vertex representing the key in the BST. In the main function, write a for loop that will go through the individual vertices and extract their level numbers using the getLevelNumber(int nodeid) function called on an object of the class Binary Search Tree. Use these level numbers of the vertices to calculate the average number of co successful search and print the same. mparisons for a Test your code with the following values for the number of elements in the array 10, 100, 1000, 10000 The maximum value for an element in each case is 2500 As part of the output, you need not print the contents of the array. Just print the average number of compa array risons for a successful search for each of the above four values for the number of elements in the What to submit: Include both (a) and (b) in a single word document and submit (a) The complete code for the binary search tree class (including the implementation of the assignLevelNumbers0 and getLevelNumber(int) functions) and the associated classes as well as the extended main function that determines the average number of (b) Tabulate the values for the number of elements vs. the average number of comparisons for a successful search. Why is that the average number of c the number of elements? comparisons for a successful search. comparisons increases very slowly with increase in
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
