Professional Documents
Culture Documents
#include <stdio.h>
#include<time.h>
#define LOOP 2
int main()
{
a =10;
b =50;
start = clock();
for(inti = 0; i<LOOP; i++)
prod = a * b;
end = clock();
4. In the above code, replace multiplication with addition and see how the timechanges.
int main()
{
a =10;
b =50;
start = time(NULL);
for(inti = 0; i<LOOP; i++)
prod = a * b;
end = time(NULL);
II. A)
1. write down an algorithm to sort 5 numbers (say, 5 8,1,2,7) and answer the following
questions.
a. How many steps does the sortingtake?
b. Will the number of steps change if the numbers are in the order8,7,5,2,1?
c. What will happen if the count of the numbers increases( that is, 10 numbers
instead of 5, 100 numbers instead of5)
2. Consider the following code (called insertion sort) to sort ‘n’ numbers. Include
clock() in the following code in appropriate places to find the time taken for sorting.
Run the following program for different values of ‘n’ and see how the time varies.
Draw a graph to show how the running time increases as ‘n’ increases. To
understand how insertion sort works, use the link“https://visualgo.net/bn/sorting”
// C program for insertion sort
#include <stdio.h>
#include <math.h>
insertionSort(arr, n);
printArray(arr, n);
return0;
}
II.B)
1. The following is the C code for another sorting algorithm (heap sort). Include clock() in
the following code in appropriate places to find the time taken for sorting. Run the
following program for different values of ‘n’ and see how the time varies. Draw a graph
to show how the running time increases as ‘n’ increases. To understand how heap sort
works, use the link https://commons.wikimedia.org/wiki/File:Heapsort-example.gif
/*
* C Program to sort an array based on heap sort algorithm(MAX heap)
*/
#include <stdio.h>
voidmain()
{
intheap[10], no,i, j, c, root, temp;
III.
a. Write short notes of Big Onotation
b. List the complexities for various searching algorithms