You are on page 1of 5

University of Information Technology & Sciences (UITS)

School of Science and Engineering


Department of CSE
Assessment, Spring- 2020
Course Title: Algorithms
Course Code: CSE 213
Marks: 50

1. (a) Define Minimum Spanning Tree. Prim’s and Kruskal’s both are used to
calculate Minimum Spanning Tree. Explain where you should use kruskal as
opposed to Prim or vice versa ?

(b) One day, one of your friends has offered you a dinner .The items are :

Polao Mutton Borhani Chicken Roast Mushroom-Salad


400gm 250gm 200gm 300gm 150gm
200TK 750TK 200TK 400tk 350TK

You can consume at most 800 gm at dinner. Which items at how much quantity
should you take to maximize the cost?

(c) UITS is now in its new campus . In new Campus , all the departments are
connected with wire like this diagram

Page 1 of 4
We want to connect to department in such a way that need as less as wire possible.Find
that connected the campus and calculate the length of wire needed to connect all .

2. (a) Explain the concept of Algorithm . Write down the characteristics of


Algorithms

(b) In UITS , There are some teachers and Students .Teachers and Students can
have their own priority list for thesis assigning . Given Preference to the teacher
, Assign the student to teachers that have a stable situation.

Teachers Priority

AI A D B C

KMK D B C A

ATK A C D B

UP D B A C

Students Priority

A ATK AI UP KMK

B AI KMK ATK UP

C KMK AI UP ATK

D ATK UP AI KMK

3. (a) Merge Sort and Quicksort both use Divide and Conquer Approach . But which
one is better . If have different perspectives -Explain

(b) Suppose , You have an unsorted array [9, 3, 6, 11, 2, 5, 8] . Show the first
Iteration by placing 8 at right Place

Page 2 of 4
4. (a) What will be the time complexity of the following code(s) ?

i ) #include <stdio.h>
int main(){
int i , j,n;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf(“Hello UITS”);
}
}
}

ii) #include <stdio.h>


int main(){
int i , j,k,n;
for(i=0;i<n;i++){
printf(“Hello UITS”);
}
for(i=0;i<n;i++){
printf(“Algorithm is a nice course”);
}
for(i=0;i<n;i++){
printf(“I love coding”);
}
}

iii) #include <stdio.h>


int main(){
int i , j,k,n;
scanf(“%d”, &n);
if(n > 0){
printf(“Positive Number”);
}
else{
printf(“Negative Number”);
}

Page 3 of 4
(b) Find the time complexity of the following code

public int binarySearch (int target, int[] array, int low, int high) {
if (low > high)
return -1;
else {
int middle = (low + high)/2;
if (array[middle] == target)
return middle;
else if(array[middle] < target)
return binarySearch(target, array, middle + 1, high);
else
return binarySearch(target, array, low, middle - 1);
}
}

5. Two Students - Fahim and Tanima. They are now in the CSE Department of
Algorithms class. Both are asked to go to the VC Room .Tanima doesn’t care
about the future. He chose the path which is shortest from the current node
whereas Fahim is very serious. He makes decisions about what can happen in
future .

Page 4 of 4
i) Calculate the distance needed to reach the VC room for Tanima.

ii) Step by Step, Measure the distance Fahim need to reach the same
destination.

iii) Explain your logic on when we should use Dynamic programming over
Greedy Method in such a scenario.

Page 5 of 4

You might also like