DSA Theory Final
DSA Theory Final
IMPORTANT INSTRUCTIONS:
_________________________
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)
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
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];
Example:
Input value: 125
Output: Found
Input value: 9
Output: Not Found
#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];
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.
To carter collision we use, linear probing to store ascii value. If collision we store key at computed hash table
index + 1.
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