Assignment No. 1: Total Marks: Due Date

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Assignment No.

1 Total Marks: 20

Semester: Spring 2022


Due Date: 20/06/2022
CS301 – Data Structures

Instructions
Please read the following instructions carefully before submitting the assignment solution:
It should be clear that your assignment will not get any credit/marks if:
o Assignment is submitted after due date.
o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).

Recommended Tools
 Dev C++

Assignment Submission Instructions


You have to submit only “.cpp” file of your code on the assignments interface from your LMS
account.
Assignment submitted in any other format will not be accepted and will be scaled with
zero marks. No excuse will be accepted on submitting solution file in any other format.
For any query related to assignment, please contact [email protected].

Problem Statement:
You are required to create a program using C++ programming language to implement binary
search tree (BST).

Use the information of students given in the following table as data source.
Marks 10 5 14 3 7 9 18 15 13 17 100
Gender Female Male Male Male Male Female Female Female Female Male Male
You are required to create two binary search trees using above data such that first BST should
have information (marks and gender) of only “male” students while second BST should have
information of only “female” students.

Important Instructions:
You need to fulfill the following requirements while solving the assignment task.
1. For the construction of BST use only class, the use of struct will be considered an
invalid solution.
2. Read the whole data of “Marks” and “Gender” arrays and save into BST on the basis of
marks.
3. The marks and gender information of all female students should be saved into one BST
and information of male students should be saved into another BST.

4. After constructing both BSTs, you need to perform in-order traversal of both BSTs on the
basis of marks.
5. In-order traversal will be on the basis of marks but you need to show complete
information (marks and gender) of all students in a BST on the console (command
prompt).
6. Graphical representation of both BSTs is showing below. You don’t need to show BSTs
graphically. We provide you graphical representation of in-order traversal for the
checking of your solution with actual solution.
7. You need to ensure that you read the arrays (marks and gender arrays) from left to right
each element one by one.
Hints:
 Create two BST objects.
 Consider marks and gender rows of given data as separate arrays.
 The structure of classes which you need to create in the required program is given below.
TreeNode

--gender:string
-marks:int None Member
-Left:TreeNode Functions
-Right:TreeNode
main()
+setMarks()
+getMarks()
+setGender()
+getGender()
+getLeft()
+setLeft()
+setRight()
+getRight()
+isLeaf b()
+insert ()
+inorder()

Structure of classes need to be created for required program.


Graphical Representation:

5
Male

3 14
Male Male

7 17
Male Male

100
BST of Male Students Male

10
Female

9 18

Female Female

15
Female

BST of Female Students

13
Female
Sample Output:

Lectures Covered: Lecture # 9 - 15


Due Date: Monday, June 20, 2022.

You might also like