PA2 Manual
PA2 Manual
PA2 Manual
Assignment 2
1. Students must not share the actual program code with other students.
2. Students must be prepared to explain any program code they submit.
3. Students cannot copy code from the Internet.
4. Students must indicate any assistance they received.
5. All submissions are subject to automated plagiarism detection.
6. Students are strongly advised that any act of plagiarism will be reported
to the Disciplinary Committee.
Learning Outcomes
Pre-requisites
Linux Environment
Your code must be compiled in the Linux environment using either the
Windows Subsystem for Linux or a Linux Distribution via Dual Boot.
You are good to go if you are already running Linux or MacOS, but for those
who are on Windows. You can use one of the two options below; the safest
one is to go with WSL as we suggest, Dual Boot, only if you have an idea of
what you are doing.
Option 1: WSL
8. Inputting the command above will take some time and once it does,
you’ll have it installed.
Connecting to WSL:
- You can either open a controlled environment of the subsystem in VSCode
or simply integrate it within your terminal
-> Open the remote window (little blue box) at the bottom left, after which
you’ll get the following pop-up
Case 2:- Integration within the terminal
At the top right side of the terminal, you’ll see the option to open a WSL
terminal within.
Submission guidelines:
Zip the complete folder and use the following naming convention:
PA2_<rollnumber>.zip
For example, if your roll number is 25100045, then your zip file name should
be:
PA2_25100045.zip
If you submit your work late for any assignment once your 5 “free” late days
are used, the following penalty will be applied:
● 10% for work submitted up to 24 hours late
● 20% for work submitted up to 2 days late
● 30% for work submitted up to 3 days late
● 100% for work submitted after 3 days (i.e., you cannot submit
assignments more than 3 days late after you have used your 5 free late
days.
In this part, you will be applying what you learned in class to implement
different functionalities of a tree efficiently. The basic layout of a general tree
is given to you in the Tree.h file.
The template node in Tree.h represents a node in the tree. The class Tree
implements the general tree, which contains a pointer to the root and other
function declarations.
NOTE:
A node in this tree can have any number of children.
Member functions:
Write implementation for the following methods as described here.
Tree(shared_ptr<node<T,S>> root)
Simple default constructor.
int findHeight()
Returns the height of the tree.
NOTE: A tree with only root has height 0.
void deleteTree()
Deletes the entire tree.
The internet is in its nascent stages, rapidly evolving into a global network.
With an increasing number of domains being registered, there's a pressing
need to organize and manage these domains efficiently. You have been hired
to design a hierarchical system for the Domain Name System (DNS), a critical
component of the Internet's infrastructure.
Your task is to develop a DNS1 hierarchy using the general tree structure
implemented in Part 1 of your assignment. The DNS hierarchy will structure
and categorize domains and subdomains to reflect their relationships and
dependencies.
1. Root Node:
At the top of the hierarchy is the ROOT node, representing the starting
point of the DNS (already done for you).
2. TLD Nodes:
The next level contains nodes for Top Level Domains (TLDs) like .com,
.org, .net, etc. These nodes are children of the ROOT node.
3. Domain Nodes:
Under each TLD node, there will be domain nodes. For example, under
.com, there could be google, facebook, etc.
4. Subdomain Nodes:
Each domain node can have multiple subdomain nodes. For instance,
under google, there could be maps, mail, etc.
5. Further Levels:
1
It is a simplified version; actual DNS is more complex
Member functions:
Write implementation for the following methods as described here.
DNS()
Simple default constructor, which creates the ROOT node.
int numRegisteredTLDs()
Returns the count of nodes at the second level.
The tree on the previous page was created by the following function calls:
addWebpage(“oxford.org/donate”)
addWebpage(“google.com/maps”)
addWebpage(“google.com/drive/create”)
addWebpage(“rizq.org/users/login”)
addWebpage(“google.com/drive/upload”)
1. getAllWebpages(“org”)
2. getDomainPages(“google”)
NOTE:
● No creation of additional helper functions is allowed.
● Only methods defined in Part 1 should be used for the implementation.
● Visualizing the tree structure on paper with sample domains is
recommended to facilitate understanding and implementation.
PART 3: BALANCED SEARCH TREES marks = 30
For this part, the following simplified node class is provided to store the
resume:
node(S n, S g, T w) {
this->fullName = n;
this->gender = g;
this->workExperience = w;
left = NULL;
right = NULL;
height = 1;
}
};
NOTE:
● You can assume that fullName is a string without spaces and does not
contain any invalid characters.
● gender is represented as ‘M’ or ‘F’.
● workExperience represents the work experience of the applicant in
months.
Implement the AVL class to store the simplified resumes of all applicants.
Member functions:
Write implementation for the following methods as described here.
AVL(bool isAVL)
Simple default constructor to initialize the isAVL flag. If the isAVL flag is set, insertions
and deletions will follow the AVL property. Otherwise, it will be a simple BST.
void insertNode(shared_ptr<node<T,S>> N)
Inserts the given node into the tree such that the AVL (or BST) property holds.
void deleteNode(T k)
● Deletes the node with the given key such that the AVL (or BST) property holds.
● As a convention, while deleting a node with 2 children, the new root should be
selected from the left subtree.
shared_ptr<node<T,S>> searchNode(T k)
Returns the pointer to the node with the given key. NULL is returned if the key doesn’t
exist.
int height(shared_ptr<node<T,S>> p)
Returns the height of the tree.
NOTE: A tree with only a root has a height 1.
TIPS:
● Start by implementing all operations for a simple BST.
● Make additional helper functions for balancing the tree and the left
and right rotations.
● Don’t forget to update the height of nodes after insertion/deletion.
PART 4: ETHICAL IMPLICATIONS marks = 20
1. Murtaza
2. Ayain
3. Abdullah
TASK 1:
Your next task is to explore how this bias varies if you change your shortlisting
algorithm. Your current approach has been stated above. You propose two
alternatives:
Algorithm 1:
Shortlist applicants according to the in-order traversal of the tree
Algorithm 2:
Shortlist applicants according to the level-order traversal of the tree
Algorithm 1
Algorithm 2
You decide to write code to compare the two strategies. Implement the
following functions:
You decide to raise your concerns about this bias to Amazon’s CEO. However,
he isn’t convinced by your argument. To help solidify your argument, you
decide to prove the existence of the bias (in the original algorithm).
Implement the following function to reveal the bias in the automated resume
screening system:
Describe what these ratios mean. Are they significant to prove that there is
bias in the tree due to differences in average work experience?
PART 5: GRAPHICAL ANALYSIS marks = 5
This section will focus on the graphical analysis of the performance data
collected from the previous tests. The objective is to visually interpret and
compare the efficiency of BST and AVL Trees implemented in part 3.
Objectives:
We’ve provided you with relevant scripts in the test suite to generate graphs
for you in the src/Part 5 directory. You just need to run them and then use the
graphical data to conclude the relative performance of the BST and AVL Trees.
Deliverables:
1. Generated graphs
2. A summary detailing the insights gained from the graphical analysis is
at this link.
Running and Testing Code:
The comprehensive testing suite developed for the assignment can be easily
accessed and executed through a user-friendly interface. The following steps
will guide you through running and testing various parts of the assignment:
g++ Test.cpp
./a.out
Upon starting the program, you will be presented with a menu interface
listing all available test parts and their corresponding indices and allocated
marks.
To run a specific test, enter the index number corresponding to that test
when prompted.
After selecting a test, the program will automatically compile and execute the
respective C++ file for that test. Some tests may take some time; your
patience is greatly appreciated.
Observe the output in the console for the results of the test. This may include
success messages, error logs, performance metrics, or graphical output,
depending on the specific test.
After a test is completed, the menu interface will reappear, allowing you to
run additional tests or exit the program.
MARKS DISTRIBUTION
Part Marks
Part 1: General Tree 20