Re: CS301 Assignment 2 Solution and Discussion
Assignment No. 02
CS301- Data Structures
Total Marks: 20
Due Date: 17-Jun-2020
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
The assignment is submitted after due date.
The submitted assignment is other than .CPP file.
The submitted code does NOT compile.
The submitted assignment does NOT open or file is corrupted.
The assignment is copied (from other student or ditto copy from handouts or internet).
For clarity and simplicity, you are required to upload/submit only one .CPP file.
Note: Use only Dev-C++ IDE.
The objectives of this assignment are;
To make you familiar of programming with Tree data structure
To traverse Binary Search Tree (BST) using different techniques
To perform some basic operations on BST
For any query about the assignment, contact at [email protected]
Total Marks: 20
As you know, Binary Search Tree (BST) has property that on the addition of a node in the tree, we compare it with root node. If new node is less than root node, it can be added to the left sub-tree. Otherwise, it will be added to the right sub-tree. So, the BST will have numbers (or nodes) less than the root in the left sub-tree and the numbers greater than the root will be in the right sub-tree.
Following is a snapshot of Binary Search Tree (BST).
You are required to develop a C++ program implementing Binary Search Tree (BST) data structure for the above scenario.
For this you need to;
- Construct Binary Search Tree, based upon above given tree data
- Calculate minimum node (or number), maximum node, height and total number of nodes for BST
Your solution must contain a tree node class named as TNode, insert() method, buildTree() method, minNode() method, maxNode() method, treeHeight() method and countNodes() method. You should call BuildTree() method in main() method and call insert() method inside BuildTree() method so that insert() method can actually add nodes in BST.
You must call the above-mentioned methods from main to calculate minimum node, maximum node, height and total number of nodes for the BST.
Remember, the height of root node is 1 while depth or level of root node is 0 in tree.
Make sure to follow class name, method names and variable/objects names as mentioned above in the scenario. Moreover, your solution must be according to the Required Output. Otherwise, you will get Zero marks.
Lectures Covered: Lecture No. 09 to 16.
Deadline: Your assignment must be uploaded / submitted on or before, Jun 17, 2020.