## Description

β’ To verify empirically Theorem 12.4 (Chapter 12, Textbook) that states:

βThe expected height h(n) of a randomly built binary search tree on n distinct keys is O(lg n).β What you need to do:

1. (10 points) Implement the Tree-Insert(T,z) operation on a binary search tree.

2. Repeatedly insert π randomly picked numbers in a binary search tree and collect the height π(π) of the obtained tree.

β(π) is the height of the binary search tree containing n elements. For simplicity, no need to enforce that the keys are distinct. In other words, you do need to check whether a number is already in the tree. 3. (60 points = (20 points per function/plot)) Plot on three separate graphs the plots of the functions β(π), β(π), and β(π) versus ππ(π) π π πππ(π) n.

4. (30 points: 10 points per plot) Discuss the three plots and conclude regarding the asymptotic growth of h(n). Decide whether your measurements confirm Theorem 12.4.

Objective:

The objective of this programming assignment is to verify empirically Theorem 12.4 that states that βthe expected height of a randomly built binary search tree on n distinct keys is O(lg n).β

In order to conduct this experiment, you must implement in your preferred language (available on Tux Machines) the Tree-Insert(T,z) operation. Below, I explain in pseudocode the program you must write to collect data and verify Theorem 12.4. You do not need to enforce that the keys are distinct.

Program to implement

collectData()

for n = 250 to 20,000 by 250 // 250, 500, 750, 1,000, β¦. 20,000

sum_heightn = 0

for j = 1 to 5 do //Take 5 measurements mj for j=1 to 5 for i = 1 to n

pick randomly a number p in the range [0-40,000]

create a node z

set z.key = p

Tree-Insert(T,z)

Measure the height hj of the tree

Discard Tree (free memory)

sum_heightn += hj

collect Height(n)= sum_heightn/5 // Average height for n

Write in a file F the value n and Height(n)

Data Analysis

β(π) β(π) β(π)

Use any plotting software (e.g., Excel) to plot the functions , , and where β(π) is the value Height(n) you collected in ππ(π) π π πππ(π)

File F. File F is the file produced by the program you implemented. Discuss your results based on the plots. Decide whether Theorem 12.4 (Chapter 12, Textbook) is correct. This theorem states βThe expected height h(n) of a randomly built binary search tree on n distinct keys is O(lg n).β

Start inserting your answers on the next page >>>>>>>>>>>>>>>>>>>>

Start Answering On This Page Where Indicated In Blue:

1. (10 points) Implement the Tree-Insert(T,z) operation on a binary search tree.

Insert here a snapshot of your implemented Tree-Insert(T,z) method in your preferred language…

2. Repeatedly insert π randomly picked numbers in a binary search tree and collect the height π(π). β(π) is the height of the binary search tree containing n elements. For simplicity, no need to enforce that the keys are distinct. In other words, you do need to check whether a number is already in the tree.

Submit/Attach your program CollectData (to collect data) separately on Canvas for this assignment. The program is your implementation of the pseudocode provided above to collect data. You can use any language as long as it is already available on Engineering Unix Tux machines. Include here the directives to compile and execute your program CollectData.

3. (60 points (20 points per function/plot)) Plot on three separate graphs the same plot of the functions β(π), β(π), and β(π) ππ(π) π π πππ(π) versus n.

β(π)

Insert here the plot for ……..

ππ(π)

β(π)

Insert here the plot for ……..

π π

β(π)

Insert here the plot for ……..

πππ(π)

4. (30 points: 10 points per plot) Discuss the three plots and conclude regarding the asymptotic growth of h(n). Decide whether your measurements confirm Theorem 12.4.

β(π)

Discuss here the plot ……..

ππ(π)

β(π)

Discuss here the plot ……..

π π

β(π)

Discuss here the plot ……..

πππ(π)

Conclude the validity of Theorem 12.4

Report

β’ Insert your answers where indicated. This file with your inserted answers will contain, explain, and discuss the plots.

β’ In addition, the above report (this file) must contain the following information: o whether your data collection program works or not (this must be just ONE sentence) o the directions to compile and execute your program β’ Good writing is expected.

β’ Recall that answers must be well written, documented, justified, and presented to get full credit.

β’

What you need to turn in:

β’ Electronic copy of your source data collection program (separately attached to this assignment)

β’ Electronic copy of this file (including your inserted answers) (separately attached). Submit the file as a Microsoft Word or PDF file.

Grading

β’ See points distribution with questions/tasks.

## Reviews

There are no reviews yet.