Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Federal Urdu University of Arts, Science and Technology,

Islamabad
Department of Computer Science
Mid-Term Examination Fall 2020
Analysis of Algorithm Tuesday 29th Dec, 2020
Ms. Sabira Feroz BS(CS) 4 (A & B) Morning
Duration: 4 Hours Total Marks: 30
 Submit the paper in a document with pdf format and the document name should be
your full name.
 Make sure that you will submit your paper before 01:00 pm. After due time, it will not
be accepted.
 Plagiarism is strictly prohibited. If paper is found to be plagiarized then it will be
marked negative.
 Attempt all questions & be neat.

Q 1. Write the algorithm of insertion sort to arrange element in descending 06 Marks


order. Take the first 8 digits of your CNIC number. Sort the digits in
descending order using the insertion sort. Show the complete working of
each step of the algorithm.
Q 2. Take the first 8 digits of your CNIC number. Sort the digits in ascending order 06 Marks
using the merge sort.
Q 3. a. Find the Time Complexity T(n) of the following algorithms: 06 Marks
void function (int n)
{
if (n>0)
{
for( int i = 1; i < n; i = i*5)
{
cout<< i;
}
}
cout<< “end”;
}
b. Find the average, worst and best case Complexity of the following
program:
int display()
{
int n= 6;
int sum= 0;
for(int i = 2; i <= n-3; i++)
{
cout<< i;
for( int j = 3; j <= i-2; j++)
{
sum= sum + i + j;
}
}
return sum;
}
Q 4. Find the Time Complexity of the following recursive algorithm using tree 06 Marks
and substitution method:
void function (int n)
{
if (n>0)
{
cout<<n;
function(n-1);
function(n-1);
function(n-1);
}
cout<< “end”;
}
Q 5. Find the Time Complexity of the following recursive dividing algorithm 06 Marks
using tree and substitution method:
void function (int n)
{
if (n>0)
for( int i = 0; i < n; i = i++)
{
cout<< i;
}
function(n/5);
function(n/5);
}

Good Luck!!

You might also like