logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Vishal FogatComputer science
(5/5)

535 Answers

Hire Me
expert
Jon CulshawwComputer science
(5/5)

735 Answers

Hire Me
expert
Ivy GeePsychology
(5/5)

680 Answers

Hire Me
expert
Connor BlackStatistics
(5/5)

977 Answers

Hire Me
C++ Programming

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?

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

385 Experts Online