Ada 1.2
Ada 1.2
Practical: 1.2
int main() {
int n = 10000;
int *arr = (int*)malloc(n * sizeof(int));
double total_time = 0;
srand(time(NULL));
for (int j = 0; j < 10; j++) {
for (int i = 0; i < n; i++) {
arr[i] = rand() % 10000;
}
total_time += measureSortingTime(arr, n);
}
double average_case_time = total_time / 10;
printf("Average time taken: %f seconds\n\n", average_case_time);
free(arr);
return 0;
}
1) Best Case:
● OUTPUT:
2) Average Case:
● OUTPUT:
3) Worst Case:
● OUTPUT:
➢ Recursive method:
● CODE:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
2
CKPCET(IT) ANALYSIS AND DESIGN OF ALGORITHMS (3150703)
swap(&arr[min_idx], &arr[index]);
selectionSortRecursive(arr, n, index + 1);
}
int main() {
int n = 10000;
int *arr = (int*)malloc(n * sizeof(int));
free(arr);
return 0;
}
3
CKPCET(IT) ANALYSIS AND DESIGN OF ALGORITHMS (3150703)
1) Best Case:
● OUTPUT:
2) Average Case:
● OUTPUT:
3) Worst Case:
● OUTPUT:
▪ Comparison Table:
CASE Iterative Recursive
Best Case 0.051 Seconds 0.051 Seconds
Worst Case 0.048 Seconds 0.04 Seconds
Average Case 0.056 Seconds 0.056 Seconds
4
CKPCET(IT) ANALYSIS AND DESIGN OF ALGORITHMS (3150703)