Binary search trees using C++ templates
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?
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
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
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme