TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
Lab12 dsa bsee20075
1. Electrical Engineering Department
CS243L: Data Structures and Algorithms
Course Instructor: Momina Azam Dated: January 17, 2022
Lab Engineer: Muhammad Usama Riaz
Semester: 3rd
Session: 2020-2024 Batch: BSEE2020
Lab. 12 Binary Search Tree
Name Roll No Lab ReportMarks/100 Total Marks
(Scaled out of 10)
MUHAMMAD UMER
SHAKIR
BSEE20075
Checked on:
Signature:
2. 12.1 Objective
The goal of this handout is to observe and implement the basic of a data structure Binary search
tree.
12.2 Equipment and Component
Component
Description
Value Quantity
Computer Available in lab 1
11.3 Conduct of Lab
1. Students are required to perform this experiment individually.
2. In case the lab experiment is not understood, the students are advised to seek help from
the courseinstructor, lab engineers, assigned teaching assistants (TA) and lab attendants.
11.4 Theory and Background
Binary Search Tree is a node-based binary tree data structure which has the following
properties: The left sub-tree of a node contains only nodes with keys lesser than the node's
key. The right sub-tree of a node contains only nodes with keys greater than the node's key.
Lab Tasks [10 Mark]
Q.1 Binary Search Tree
The structure of a node in the tree:
Every node in the tree must have the provision to hold:
1. data for the user
2. A pointer that can point to the node that is the left child
3. A pointer that can point to the node that is the right child
Implement a class called BSTree (for Binary Search Tree)
Data member:
Must be a Node pointer that points to the root Node.
Interface:
Add Function:
1. The function takes data as an argument.
2. It must create the node on the heap using new. Both pointers of the new Node left and right ones
3. will point to NULL.
3. Start from the root Node
4. Compare key of the new node with the key at this node.
5. If key at this Node is larger go to the Node pointed to by the right pointer of this Node.
6. If key at this Node is smaller go to the Node pointed to by the left pointer of this Node.
7. At each Node follow the steps from step 4 till you hit a pointer that points to NULL.
8. Attach the new Node you have created to this pointer.
When the tree is empty be sure to make the root pointer in the BSTree object point to the first node
you add.
4. #include<iostream>
using namespace std;
class NODE
{
public:
int INFORMATION;
NODE *LEFT;
NODE *RIGHT;
}*root;
class Binarysearchtree
{
public:
void insert(NODE *, NODE *);
void display(NODE*, int);
Binarysearchtree ()
{
root = NULL;
}
};
void Binarysearchtree::insert(NODE *tree, NODE *newnode)
{
if (root == NULL)
{
root = new NODE;
root->INFORMATION= newnode->INFORMATION;
root->LEFT = NULL;
root->RIGHT = NULL;
cout<<"Root Node is Added"<<endl;
return;
}
if (tree->INFORMATION == newnode->INFORMATION)
{
5. cout<<"Element already in the BS tree:"<<endl;
return;
}
if (tree->INFORMATION > newnode->INFORMATION)
{
if (tree->LEFT != NULL)
{
insert(tree->LEFT, newnode);
}
else
{
tree->LEFT = newnode;
(tree->LEFT)->LEFT= NULL;
(tree->LEFT)->RIGHT = NULL;
cout<<"Node Added To Left of bts"<<endl;
return;
}
}
else
{
if (tree->RIGHT != NULL)
{
insert(tree->RIGHT, newnode);
}
else
{
tree->RIGHT = newnode;
(tree->RIGHT)->LEFT = NULL;
(tree->RIGHT)->RIGHT = NULL;
6. cout<<"Node Added To Right of bts"<<endl;
return;
}
}
}
void Binarysearchtree::display(NODE *ptr, int level)
{
int i;
if (ptr != NULL)
{
display(ptr->RIGHT, level+1);
cout<<endl;
if (ptr == root)
cout<<"Root->: ";
else
{
for (i = 0;i < level;i++)
cout<<" ";
}
cout<<ptr->INFORMATION;
display(ptr->LEFT, level+1);
}
}
int main()
{
int number, num;
Binarysearchtree bst;
NODE *temp;
while (1)
{
cout<<"-----------------"<<endl;
cout<<"1:Insert Element in the BST: "<<endl;
cout<<"2:Display BST :"<<endl;
cout<<"3:Quit"<<endl;
7. cout<<"-----------------"<<endl;
cout<<"Enter your choice number : ";
cin>>number;
switch(number)
{
case 1:
temp = new NODE;
cout<<"Enter the number to be inserted : ";
cin>>temp->INFORMATION;
bst.insert(root, temp);
case 2:
cout<<"Display BST:"<<endl;
bst.display(root,1);
cout<<endl;
break;
case 3:
exit(1);
default:
cout<<"Wrong choice"<<endl;
}
}
}
8.
9. Student Name Registration# Batch: EE-2020
Assessment Rubrics
Method: Lab reports and instructor observation during lab sessions.
Outcome assessed:
a. Ability to conduct experiments, as well as to analyze and interpret data (P)
b. Ability to function on multi-disciplinary teams (A)
c. Ability to use the techniques, skills, and modern engineering tools necessary for engineering practice (P)
Performance metric Mapping (task no.
and description)
Max
marks
Exceeds expectation Meets expectation Does not meet expectation Obtained
marks
1. Realization of
experiment (a)
1 Functionality 40 Executes without errors excellent
user prompts, good use of
symbols, spacing in output.
Through testing has been
completed (45-41)
Executes without errors, user
prompts are understandable,
minimum use of symbols or spacing
in output. Some testing has been
completed (40-21)
Does not execute due to syntax errors,
runtime errors, user prompts are
misleading or non-existent. No testing has
been completed (20-0)
2. Teamwork (b) 1 Group
Performance
5 Actively engages and cooperates
with other group member(s) in
effective manner (5-4)
Cooperates with other group
member(s) in a reasonable manner
but conduct can be improved (3-2)
Distracts or discourages other group
members from conducting the experiment
(1-0)
3. Conducting
experiment (a, c)
1 On Spot
Changes
10 Able to make changes (5-4) Partially able to make changes (3-2) Unable to make changes (1-0)
2 Viva 10 Answered all questions (5-4) Few incorrect answers (3-2) Unable to answer all questions (1-0)
4. Laboratory safety
and disciplinary rules
(a)
1 Code
commenting
5 Observes lab safety rules;
adheres to the lab disciplinary
guidelines aptly (5-4)
Generally, observes safety rules and
disciplinary guidelines with minor
lapses (3-2)
Disregards lab safety and disciplinary rules
(1-0)
5. Data collection (c) 1 Code Structure 5 Excellent use of white space,
creatively organized work,
excellent use of variables and
constants, correct identifiers for
constants, No line-wrap (5-4)
Includes name, and assignment,
white space makes the program
fairly easy to read. Title, organized
work, good use of variables (3-2)
Poor use of white space (indentation, blank
lines) making code hard to read,
disorganized and messy (1-0)
6. Data analysis (a, c) 1 Algorithm 20 Solution is efficient, easy to
understand, and maintain (5-4)
A logical solution that is easy to
follow but it is not the most
efficient (3-2)
A difficult and inefficient solution (1-0)
7. Computer use (c) 1 Documentation 5 Timely documented (5-4) Late documented (3-2) Not documented (1-0)
Max Marks (total): 100 Obtained Marks (Total):
Lab Engineer Signature: ________________________