0% found this document useful (0 votes)
3K views8 pages

DSA Theory Final

The document provides instructions for a final examination for a Data Structures and Algorithms course. It lists the subject, faculty, date, time allowed, maximum marks, and important instructions for students taking the exam. The exam contains 3 questions related to applying knowledge of data structures, analyzing algorithm efficiency, and traversing a graph using breadth-first and depth-first search.

Uploaded by

Talha Syed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views8 pages

DSA Theory Final

The document provides instructions for a final examination for a Data Structures and Algorithms course. It lists the subject, faculty, date, time allowed, maximum marks, and important instructions for students taking the exam. The exam contains 3 questions related to applying knowledge of data structures, analyzing algorithm efficiency, and traversing a graph using breadth-first and depth-first search.

Uploaded by

Talha Syed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

North Campus

Final Examination Spring Semester 2021

Subject Data structures and algorithm Program BS(CS)


Time
Faculty Sabeeh Ahmed 3 Hours
Allowed
Maximum
No. of Students 40
Marks
OBE Target CLO-1,2, PLO-1,2, and C 3& 4
Student Name Syed Talha Ur Rehman Student ID 12232
Date & Time 3-6-2021
Section Code
Slot 08:30 – 11:30

IMPORTANT INSTRUCTIONS:

Read the Instructions carefully.

1. Attempt all questions on Question Paper.


2. Adjust your font in the given space.
3. Mobile Phones are strictly not allowed in the Examination Hall. If anyone’s cell phone
is found switched on, it will be considered as attempt of cheating.
4. Any attempt to use unfair means will disqualify you from the examination
5. Any other Programmable device is strictly not allowed in the Examination Hall.
6. Students are not supposed to ask questions after the first fifteen minutes of examinations.
7. Please do not use pencils except for underlining or for diagrams.
8. Do not write anything on your hand, clothes or calculators, which may cause to cancel your exam paper.
9. The examination authority will not return the script to the examinees once they have submitted their
answer script.
10. All students must bring their own stationary and calculators. Borrowing in the examination hall is
strictly prohibited.
11. All students shall comply with any other instruction, written or oral, given by the examiner / invigilator
in the examination hall.
12. Please follow any other instructions provided by the examiner in the question paper.

_________________________

Faculty Signature
Q. No. 1 CLO-1, PLO-1 and C3 Apply the acquired knowledge regarding Data structure Max Marks 10

A) Suppose the numbers 7 , 5 , 1 , 8 , 3 , 6 , 0 , 9 , 4 , 2 are inserted in that order into an initially empty binary
search tree. The binary search tree uses the usual ordering on natural numbers.
Show
A) In order
0123456789
B) pre order
7510324689
C) post order
0243165897

B)

From the given tree state predict


1. Degree of tree = 2
2. Degree of node G = 2
3. Level of node H = 3
4. Prove that formula to find maximun number of node is not applicable here , along with reason
The tree is unbalance that’s why formula to find maximun number of node is not applicable here.
5. Post order, pre order and in order traversing
Inorder: ADEFGHJMFQRT
Preorder: JDAGEFHRMPQT
Postorder: AEFHGDMPQTRJ

Q. No. 2 CLO-1, PLO-1 and C3 Apply the acquired knowledge regarding Data structure Max Marks 10

Suppose you works in a library and have the id’s of 12 books as follows
2345 , 125 , 85 , 969 , 789 , 12 , 487 , 66 , 4556 , 48 , 7987 , 412

If you need to made a simple program


a) Which data Structure will you chose in order to store these Book ID’s? Justify your answer

An array can be use in order to store these book ID’s because it is the most simplest and widely use
data structure.
b) Does the physical arrangement of books and data structure you chose to store book ID’s have any
link with each other? Chose either YES or NO and Give reason why your answer is YES and give
reason if your answer is NO

Yes the physical arrangement of books and data structure has a link because we don’t know how
books are arrange in library. If it is arrange randomly we won’t be able to search it by binary search…
etc.

c) Write a C/C++ program that saves above ID’s in your chosen data structure

#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, array[100],c;
cout<<"NAME : SYED TALHA UR REHMAN , ID : 12232"<<endl;
cout<<"Enter number of element"<<endl;
cin>>n;
cout<<"enter "<<n<<" integers:"<<endl;

for(c=0;c<n;c++)
cin>>array[c];

cout<<"Array inserted: "<<endl;


for (int i=0;i<n; i++)
{
cout<<array[i]<<endl;
}
return 0;
}
d) [Connected with part c] Take integer value as an input that searches from values present in data
structure and give output “FOUND” if value matches and, “ DID NOT FOUND” if value didn’t matches,
Discuss the searching technique you used with reason

Example:
Input value: 125
Output: Found

Input value: 9
Output: Not Found

Array is not arranged so I use linear search technique.

#include <iostream>
using namespace std;
int search(int arr[], int n, int x)
{
int i;
for (i = 0; i < n; i++)
if (arr[i] == x)
return i;
return -1;
}

int main()
{
int n, arr[100],c,x;
cout<<"NAME : SYED TALHA UR REHMAN , ID : 12232"<<endl;
cout<<"Enter number of element"<<endl;
cin>>n;
cout<<"enter "<<n<<" integers:"<<endl;

for(c=0;c<n;c++)
cin>>arr[c];

cout<<"Enter ID to find: "<<endl;


cin >> x ;

int result = search(arr, n, x);


(result == -1)
? cout << "Element is not present in array"
: cout << "Element is present at index " << result;
return 0;
}

Q. No. 3 CLO-2, PLO-1 and C4 : Analyze the efficiency of various Algorithm Max Marks 10
Here is a graph between two different campuses comprised of several location
Traverse the graph using
Breadth first search
Depth first search

3 Km 4 Km 6 Km
Expo Centre Bus
National Stadium
Stop

6 Km 1 Km 6 Km 12 Km
Sir Syed Stop Urdu University Jail Chawrangi

3 Km

Iqra 3 Km 2 Km 7 Km 8 Km 15 Km Iqra
University Allama Shabbir Rashid Minhas University
Patel Hospital Shahrah-e-Faisal
Gulshan Ahmed Road Road Main
Campus 1 Campus

9 Km

5 Km 7 Km
Waterpump Teen Hatti

BFS:
S

S 1 2 3

S 1 2 3 4 5 10

S 1 2 3 4 5 10 6

S 1 2 3 4 5 10 6 7

S 1 2 3 4 5 10 6 7 8

S 1 2 3 4 5 10 6 7 8 9

S 1 2 3 4 5 10 6 7 8 9 11

S 1 2 3 4 5 10 6 7 8 9 11 D
DFS:
S

S 1

S 1 4

S 1 4 8

S 1 4 8 11

S 1 4 8 11 D

S 1 4 8 11 D 2

S 1 4 8 11 D 2 6

S 1 4 8 11 D 2 6 10

S 1 4 8 11 D 2 6 10 3

S 1 4 8 11 D 2 6 10 3 7

S 1 4 8 11 D 2 6 10 3 7 9

S 1 4 8 11 D 2 6 10 3 7 9 5
Q. No. 4 CLO-1, PLO-2 and C4 : Analyze the working and efficiency of various Algorithm Max Marks 10

A) Consider your name, take ASCII value of each character and map all those values in a Hash table using any
method you want. mention each insertion step wise and if there is collision, mention that as well. Answer the
following questions
A) What should be the preferable Table size and why?

We consider table size greater than or equal to length of name, to store each ascii value in hash table, in this
case we consider size of hash table as length of string, for example, consider name talha.

B) What technique did you use to cater collision and why?

To carter collision we use, linear probing to store ascii value. If collision we store key at computed hash table
index + 1.

C) What is the value of load factor?

Load factor is 1, since we are considering size of hash table as length of string, number of ascii characters/
length of table, = 6/6 = 1.

B) Suppose a hash table has 11 locations, keys are placed in the table using the hash function f (x) = x mod 11, and
linear chaining is used to resolve collisions Draw a picture of the result of storing the following keys in the table: 0,
12, 42, 18, 6, 22, 8, 105, 97

You might also like