CS502 ASSIGNMENT 1 SOLUTION 2021 | CS502 ASSIGNMENT 1 FALL 2021 | CS502 ASSIGNMENT 1 2021 | FUNDAMENTALS OF ALGORITHMS | VuTech
KINDLY, DON’T COPY PASTE
Visit Website For More Solutions
www.vutechofficial.blogspot.com
Question No. 1
Part a)
Suppose one of the reputed higher educational institute working on an IT
based project which is related to the student management system. This
project has been divided into a number of modules and different teams are
working on it. One team is facing an issue in the attendance module; they
cannot find the total number of students absent in a class. Total class
strength is 100.
- You must assist the team to write an efficient algorithm to find how many students are absent in a class.
Answer:
Step 1: Start
Step 2: initialize
variable num = 1, count =
0 , abs
Step 3: Start roll call
Step 4: Repeat the steps until
num<=100
4.1
If student present
Count
= count + 1
4.2 num = num
+ 1
Step 5: abs = 100 – count
Step 6: Display “How many students are
absents: “ + abs
Step 7: Stop |
Part b)
Find the Best-case and Worst-case time of the given piece of code.
Algorithm Test (n)
{
if (n <5 )
{
printf(“%d”, n);
}
else
{
for(i=0; i<n; i++)
{
printf(“%d”, i);
}
}
}
Answer:
Best-Case: O (1)
Worst-Case: O (n)
KINDLY, DON’T COPY PASTE
Visit Website For More Solutions
www.vutechofficial.blogspot.com
Question No. 2
Merge Sort follows divide and Conquer strategy therefore it’s a Recursive
algorithm. Here is an unsorted list with eight elements.
8 |
3 |
7 |
5 |
9 |
2 |
6 |
4 |
1 - Sort the above list using Merge sort in ascending order.
2 - Build Merge sort tree for both divide and combine phases.
You are required to do the following tasks:
Answer:
8 |
3 |
7 |
5 |
9 |
2 |
6 |
4 |