Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

Can you conclude that if the elements to be inserted in a BST are given beforehand, a good strategy is to randomly permute them before constructing the BST?

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Binary search trees using C++ templates

  1. Read about how to use templates in C++
  2. Complete the following C++ templates for binary search tree:

template class Node {

private:

T x;

Node *left; // left child Node *right; // right child Node *parent; // parent node

// any other augmented information

public:

};

 

//define suitable functions here

template class BST {

private:

Node *root; // root node

int n; // total number of nodes

 

public:

 

// define suitable constructor, destructors, etc. here. int search(T x); // search x in BST

int insert(T x); //  insert  x  in  BST int remove(T x); // delete x from BST

// return k-th smallest data in the tree T order_statistics(int k)

};

Here the operators <, >, ==, <=, >=, ! = are overloaded for type T .

Define instances of above class templates for different data types T , and test that they work correctly.

 

2 Performance of binary search trees on randomly ordered input

Without loss of generality,  assume that the keys to be inserted in a BST are        1, 2, . . . , n. Let (σ(1), σ(2), . . . , σ(n)) be a random permutation of (1, 2, . . . , n) (i.e., each of the n! permutations are equally likely to be σ).

Suppose we insert keys σ(1), σ(2), . . . , σ(n) in an empty binary search tree in this order. Let Tσ be the resulting binary search tree.

Your objective is to experimentally estimate the average height of tree

Tσ. To be specific, let h(Tσ) be the height of tree Tσ. Then, average height

σ h(Tσ ) n!

Note. (i) You can try n = 128, 256, . . . , 65536 (successive powers of 2). For each n, you may generate K = 10000 permutations. Let height of binary search trees for these permutations are h1, h2, . . . , hK . Then, average height (of a random binary search tree) for n keys can be estimated by h1+h2+...+hK .

Plot this average height as a function of n. What do you observe?

 

Question: Can you conclude that if the elements to be inserted in a BST are given beforehand, a good strategy is to randomly permute them before constructing the BST?

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
502 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
655 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
927 Answers Hire Me