Daa2 1
Daa2 1
#include <stdio.h>
// Driver program
int main() {
int n;
int arr[n];
return 0;
}
0r
#include <stdio.h>
// Heapify function
void heapify(int arr[], int n, int i) {
int temp, maximum, left_index, right_index;
// HeapSorting function
void heapsort(int arr[], int n) {
int i, temp;
// Driver code
int main() {
int n;
int arr[n];
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Swap utility
void swap(long int* a, long int* b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
// Bubble sort
void bubbleSort(long int a[], long int n) {
for (long int i = 0; i < n - 1; i++) {
for (long int j = 0; j < n - 1 - i; j++) {
if (a[j] > a[j + 1]) {
swap(&a[j], &a[j + 1]);
}
}
}
}
// Insertion sort
void insertionSort(long int arr[], long int n) {
long int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
// Selection sort
void selectionSort(long int arr[], long int n) {
long int i, j, midx;
// Driver code
int main() {
long int n;
srand(time(0)); // Seed for random number generation
// Bubble sort
start = clock();
bubbleSort(a, n);
end = clock();
bubbleTime = ((double)(end - start)) / CLOCKS_PER_SEC * 1000; // Convert to milliseconds
// Insertion sort
start = clock();
insertionSort(b, n);
end = clock();
insertionTime = ((double)(end - start)) / CLOCKS_PER_SEC * 1000; // Convert to milliseconds
// Selection sort
start = clock();
selectionSort(c, n);
end = clock();
selectionTime = ((double)(end - start)) / CLOCKS_PER_SEC * 1000; // Convert to milliseconds
return 0;
}
N | Bubble Sort | Insertion Sort | Selection Sort
----|-------------|----------------|----------------
10 | 0.00 ms | 0.00 ms | 0.00 ms
15 | 0.00 ms | 0.00 ms | 0.00 ms
20 | 0.00 ms | 0.00 ms | 0.00 ms
25 | 0.00 ms | 0.00 ms | 0.00 ms
30 | 0.00 ms | 0.00 ms | 0.00 ms
35 | 0.01 ms | 0.00 ms | 0.00 ms
40 | 0.01 ms | 0.00 ms | 0.01 ms
45 | 0.01 ms | 0.00 ms | 0.00 ms
50 | 0.01 ms | 0.00 ms | 0.01 ms
Or
#include <stdio.h>
#include <math.h>
void displayTimeComplexity() {
int N;
printf(" N | Bubble Sort | Selection Sort | Insertion Sort | Merge Sort | Quick Sort (Avg) | Quick
Sort (Worst) | Heap Sort \n");
printf("---|-------------|----------------|----------------|------------|------------------|---------------------|------
------\n");
int main() {
displayTimeComplexity();
return 0;
}
N | Bubble Sort | Selection Sort | Insertion Sort | Merge Sort | Quick Sort (Avg) | Quick Sort
(Worst) | Heap Sort
---|-------------|----------------|----------------|------------|------------------|---------------------|------------
10 | 100.0 | 100.0 | 100.0 | 33.2 | 33.2 | 100.0 | 33.2
15 | 225.0 | 225.0 | 225.0 | 58.1 | 58.1 | 225.0 | 58.1
20 | 400.0 | 400.0 | 400.0 | 86.4 | 86.4 | 400.0 | 86.4
25 | 625.0 | 625.0 | 625.0 | 116.2 | 116.2 | 625.0 | 116.2
30 | 900.0 | 900.0 | 900.0 | 148.8 | 148.8 | 900.0 | 148.8
35 | 1225.0 | 1225.0 | 1225.0 | 183.3 | 183.3 | 1225.0 | 183.3
40 | 1600.0 | 1600.0 | 1600.0 | 220.0 | 220.0 | 1600.0 | 220.0
45 | 2025.0 | 2025.0 | 2025.0 | 259.0 | 259.0 | 2025.0 | 259.0
50 | 2500.0 | 2500.0 | 2500.0 | 300.4 | 300.4 | 2500.0 | 300.4
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````