#include <stdio.
h>
#include <stdlib.h>
#include <time.h>
void selectionSort(int arr[], int n) {
int i, j, min_idx, temp;
for (i = 0; i < n-1; i++) {
min_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
// Swap
temp = arr[min_idx];
arr[min_idx] = arr[i];
arr[i] = temp;
}
}
void generateRandomArray(int arr[], int n) {
for (int i = 0; i < n; i++)
{
arr[i] = rand() % 100000;
printf("%d ",arr[i]);
}
}
int main() {
int n;
printf("Enter the number of elements (n > 5000 recommended): ");
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
generateRandomArray(arr, n);
clock_t start = clock();
selectionSort(arr, n);
clock_t end = clock();
double time_taken = (double)(end - start) / CLOCKS_PER_SEC;
printf("\n Time taken to sort %d elements using Selection Sort: %.6f seconds\n",
n, time_taken);
free(arr);
return 0;
}