Dsa Ass 1
Dsa Ass 1
ASSIGNMENT 01
Marks: 2.5
CLO1, C2
Read Carefully:
• The deadline for this assignment is before 29/10/2022.
WARNING: Late submission will not be accepted. Any assignment submitted after the cutoff
time will receive zero.
• Answer should be hand written. If there is any programming related tasks then attach the
print of code properly along with the screenshots of output.
Department of Computer Science CSC-221:Data structures & Algorithm
Question 1: (CLO1)
3. Consider the given list and Infer which searching algorithm you would prefer for given
data. Show how many comparisons would be made to search “Scheduling”.
4. Assume that we have a list of votes about candidates in university election. Outline an
algorithm for determining who wins the election and show the results
[Implementation required]
umar irma sara Umar huzaifa umar Irma sara sara Irma
irma sara irma Madiha wajahat irma Sara umar maria irma
2. If we have a telephone directory with 10 million records, explain which algorithm works
best in your opinion with justification. (If your suggestion is other than studied
algorithms then discuss the working of that algorithm as well)
ANS:
3. Consider the given list and Infer which searching algorithm you would prefer for given
data. Show how many comparisons would be made to search “Scheduling”.
ANS:
Search : Scheduling
Comparison:1
s Computer Fan Network Program Resourc Scheduling Unix Wire
e
LEFT MID
RIGHT
MID
LEFT RIGHT
Scheduling FOUND!.
Department of Computer Science CSC-221:Data structures & Algorithm
4 Assume that we have a list of votes about candidates in university election. Outline an
algorithm for determining who wins the election and show the results
[Implementation required]
umar irma sara Umar huzaifa umar Irma sara sara Irma
irma sara irma Madiha wajahat irma Sara umar maria irma
SOURCE CODE
#include “iostream”
#include <string>
int main(){
int a= 0;
int b= 0;
int c= 0;
int d= 0;
int e= 0;
int f= 0;
a = a+1;
}
if(arr[i]== "imra"){
b= b+1 ;
}
else if(arr[i]== "sara"){
c=c +1 ;
}
else if(arr[i]== "huzaifa"){
d++ ;
}
else if(arr[i]== "Madiha"){
e++ ;
}
else if(arr[i]== "wajahat"){
f++ ;
}
}
}
if (b>a &&b>c && b>d && b>e && b>f){
cout <<"TOTAL VOTES ARE "<< b <<" AND IRMA WINS";
}
if (c>a &&c>b && c>d && c>e && c>f){
cout <<" TOTAL VOTES ARE "<<c <<" AND SARA WINS ";
Department of Computer Science CSC-221:Data structures & Algorithm
}
if (a>b &&a>c && a>d && a>e && a>f){
cout <<a;
cout<<"OTHERS WINS"<<endl;
return 0;
}
Output: