DAACodes
DAACodes
Quick Sort
Copy code
#include <stdio.h>
int t = *a;
*a = *b;
*b = t;
i++;
swap(&arr[i], &arr[j]);
return (i + 1);
quickSort(arr, pi + 1, high);
}
void printArray(int arr[], int size) {
printf("\n");
int main() {
quickSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
2. Radix Sort
Copy code
#include <stdio.h>
max = arr[i];
return max;
int output[n];
arr[i] = output[i];
countSort(arr, n, exp);
printf("\n");
int main() {
radixSort(arr, n);
printArray(arr, n);
return 0;
}
3. Merge Sort
Copy code
#include <stdio.h>
int n1 = m - l + 1;
int n2 = r - m;
int i = 0, j = 0, k = l;
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
k++;
arr[k] = L[i];
i++;
k++;
j++;
k++;
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
printf("\n");
int main() {
mergeSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
}
Due to the response length limit, I'll provide the remaining algorithms in smaller sets. Let me know if
you'd like the rest!
4o
You said:
yes
ChatGPT said:
ChatGPT
4. Min-Max Algorithm
Copy code
#include <stdio.h>
min = arr[i];
return min;
max = arr[i];
return max;
int main() {
int arr[] = {12, 3, 5, 1, 8};
return 0;
Copy code
#include <stdio.h>
C[0][0] = P + S - T + V;
C[0][1] = R + T;
C[1][0] = Q + S;
C[1][1] = P + R - Q + U;
int main() {
int C[2][2];
strassenMatrixMultiply(A, B, C);
printf("Result matrix:\n");
return 0;
Copy code
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#define V 5
return min_index;
int parent[V];
int key[V];
bool mstSet[V];
key[0] = 0;
parent[0] = -1;
mstSet[u] = true;
printf("Edge \tWeight\n");
int main() {
int graph[V][V] = {
{0, 2, 0, 6, 0},
{2, 0, 3, 8, 5},
{0, 3, 0, 0, 7},
{6, 8, 0, 0, 9},
{0, 5, 7, 9, 0}
};
primMST(graph);
return 0;
7. Kruskal’s Algorithm
Copy code
#include <stdio.h>
#define V 5
if (graph[i][j] != INF) {
printSolution(graph);
int main() {
int graph[V][V] = {
{2, 0, 3, 8, 5},
{INF, 5, 7, 9, 0}
};
kruskalMST(graph);
return 0;
Please let me know if you would like the remaining algorithms in the same manner!
4o
You said:
yes
ChatGPT said:
ChatGPT
Here are the remaining basic C programs for the algorithms you requested:
Copy code
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#define V 9
return min_index;
int dist[V];
bool sptSet[V];
dist[src] = 0;
sptSet[u] = true;
int main() {
int graph[V][V] = {
{0, 4, 0, 0, 0, 0, 0, 8, 0},
{0, 8, 0, 7, 0, 4, 0, 0, 2},
{0, 0, 0, 0, 0, 2, 0, 1, 6},
{0, 0, 2, 0, 0, 0, 6, 7, 0}
};
dijkstra(graph, 0);
return 0;
Copy code
#include <stdio.h>
printf("Selected Activities:\n");
int i = 0;
printf("%d ", i);
i = j;
printf("\n");
int main() {
return 0;
Copy code
#include <stdio.h>
struct Item {
};
int curWeight = 0;
curWeight += arr[i].weight;
finalvalue += arr[i].value;
} else {
break;
int main() {
int W = 50;
fractionalKnapsack(arr, n, W);
return 0;
Copy code
#include <stdio.h>
#include <limits.h>
int cost[n][n];
cost[i][i] = freq[i];
int j = i + L - 1;
cost[i][j] = INT_MAX;
if (c < cost[i][j])
cost[i][j] = c;
int s = 0;
s += freq[k];
return s;
int main() {
return 0;
Copy code
#include <stdio.h>
#define V 4
int dist[V][V];
dist[i][j] = graph[i][j];
if (dist[i][j] == INF)
printf("%7s", "INF");
else
printf("%7d", dist[i][j]);
printf("\n");
}
int main() {
int graph[V][V] = {
{INF, 0, 3, INF},
};
floydWarshall(graph);
return 0;