ADA Assignment On Analysis
ADA Assignment On Analysis
Example 1: Example 2:
Algorithm algo1 (n) Algorithm algo2 (n)
{ {
c=0;
c=0; for( i = 1; i <= n; i++) {
for(i = 0; i < n; i++) { for( i = 1; i <= 5; i++) {
for(j = n ; j > 0 ; j--) { c = c +1
if( i < j )
c = c + 1; }
} }
} }
}
Example 3 Example 7
Algorithm algo3 (n) Algorithm algo7 (n)
{ {
c=0; c=0;
for( i=n ; i >1; i = i/2) { for( i=1; i<=n*n*n, i++) {
c = c+1 c = c+1;
} }
}
}
Example 4 Example 8
Algorithm algo4 (n) Algorithm algo8 (n, m)
{ {
i = 1; c=0;
s = 1; for( i=1; i<=n ; i++) {
while ( s <=n) { for (j=1;j<=m;j++){
i++; c = c+1;
s = s + i; }
} }
}
Example 5 }
Algorithm algo5 (n) Example 9
{ Algorithm algo9 (n)
c=0; {
for (i =0; i<=3*n; i++) { i=1;j=0;
c = c+1; while (i<n){
} j=n;
} while (j>0) {
Example 6 j = j/2;
Algorithm algo6 (m , n) }
{ i = i *2;
c=0; }
for( i=1; i<=m, i++) { }
c = c+1; Example 10
} Algorithm algo10 (n)
for( i=1; i<=n, i++) { {
c = c+1; c = 0;
} for (i=n;i>=0;i=i/2) {
} for( j=0;j<i;j++ ){
c = c+1;
}
}
}
18. Sort following using Selection Sort, Bubble Sort and Insertion Sort. Show your steps.
(i) A={98,54,86,9,92,43,71}
(ii) A={E,X,A,M,P,L,E}
19. Show operation of Shell Sort on array A = {81, 23, 21, 50, 83, 33, 61, 20}
20. Illustrate the operation of Counting Sort on array A = {6, 0, 2, 0, 1, 3, 4, 6, 1, 3, 2}
21. Illustrate the operation of Radix Sort on array A = { 329, 457, 657, 839, 436, 720, 355}
22. Show operation of Bucket Sort using figure on array A = {.97, .31, .61, .46, .93, .12, .98,
.35, .17, .24}
23. Illustrate the operation of Heap Sort on array A = {5, 13, 2, 25, 7, 17, 20, 8, 4}