ADA Lab Prgms - Part-1
ADA Lab Prgms - Part-1
int main() {
int n = 10000;
int it = 0;
int tim3[10];
printf("A size Selection\n");
return 0;
}
Program 2: Quick Sort
• Hoare partition scheme: Uses first element as pivot
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
while (i < j) {
// Find the first element greater than the pivot (from the left)
while (arr[i] <= pivot && i <= high - 1) i++;
// Find the first element smaller than the pivot (from the right)
while (arr[j] > pivot && j >= low + 1) j--;
swap(&arr[low], &arr[j]);
return j;
}
int main() {
int n, i;
clock_t start, end;
double time_taken;
int arr[n];
printf("Generating %d random elements...\n", n);
srand(time(NULL));
printf("\nSorted array:\n");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\nTime taken to sort: %.6f seconds\n", time_taken);
return 0;
}
int main() {
int n, i;
clock_t start, end;
double time_taken;
int arr[n];
printf("Generating %d random elements...\n", n);
srand(time(NULL));
printf("Sorted array:\n");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
int main() {
int n, i;
clock_t start, end;
double time_taken;
int arr[n];
printf("Generating %d random elements...\n", n);
srand(time(NULL)); // Seed for random number generator
merge_sort(arr, 0, n - 1);
printf("Sorted array:\n");
for(i = 0; i < n; i++) printf("%d ", arr[i]);
int find(int i) {
while (parent[i])
i = parent[i];
return i;
}
if (unionSet(u, v)) {
printf("%d - %d : %d\n", u, v, cost);
totalCost += cost;
j++;
}
}
int main() {
int n, graph[MAX][MAX];
printf("Enter the number of vertices: ");
scanf("%d", &n);
printf("Enter the adjacency matrix (0 for no edge):\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &graph[i][j]);
if (graph[i][j] == 0)
graph[i][j] = INF;
}
}
printf("\nMinimum Cost Spanning Tree using Prim's Algorithm:\n");
primMST(graph, n);
return 0;
}