logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(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?

(5/5)
Attachments:

Related Questions

. Introgramming & 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 ma

. 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 Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

657 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

665 Answers

Hire Me
expert
Husnain SaeedComputer science

879 Answers

Hire Me
expert
Atharva PatilComputer science

590 Answers

Hire Me

Get Free Quote!

274 Experts Online