Pikachu
Pikachu
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int id, duration;
} Job;
int main() {
Job jobs[] = {{1, 3}, {2, 1}, {3, 2}};
int n = sizeof(jobs) / sizeof(jobs[0]);
JobScheduling(jobs, n);
return 0;
}
---
2. Fractional Knapsack
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int weight, value;
} Item;
int main() {
Item items[] = {{10, 60}, {20, 100}, {30, 120}};
int n = sizeof(items) / sizeof(items[0]);
int max_weight = 50;
printf("Maximum Value: %.2f\n", Knapsack(items, n, max_weight));
return 0;
}
---
#include <stdio.h>
#include <stdlib.h>
int main() {
Node* root = createNode(10);
root->left = createNode(1);
root->right = createNode(2);
root->left->left = createNode(3);
printf("Max Weight: %d\n", M(root));
return 0;
}
---
#include <stdio.h>
#include <stdlib.h>
int main() {
int A[2][2] = {{1, 2}, {3, 4}};
int B[2][2] = {{5, 6}, {7, 8}};
int C[2][2];
strassen(2, A, B, C);
printf("%d %d\n%d %d\n", C[0][0], C[0][1], C[1][0], C[1][1]);
return 0;
}
---
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int u, v, w;
} Edge;
---
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int u, v, w;
} Edge;
int compare(const void *a, const void *b) {
return ((Edge *)a)->w - ((Edge *)b)->w;
}
int main() {
int n = 4, m = 5;
Edge edges[] = {{0, 1, 2}, {1, 2, 3}, {0, 2, 1}, {2, 3, 4}, {1, 3, 5}};
for (int i = 0; i < m; i++) edges[i].w += 1;
printf("New MST Cost: %d\n", kruskal(n, edges, m));
return 0;
}
---
#include <stdio.h>
---
#include <stdio.h>
#include <stdlib.h>
int main() {
Node* root = createNode(10);
root->left = createNode(1);
root->right = createNode(2);
root->left->left = createNode(3);
printf("Max Weight: %d\n", M(root));
return 0;
}
---
#include <stdio.h>
#include <stdlib.h>
int main() {
int A[2][2] = {{1, 2}, {3, 4}}, B[2][2] = {{5, 6}, {7, 8}}, C[2][2];
strassenMultiply(2, A, B, C);
printf("%d %d\n%d %d\n", C[0][0], C[0][1], C[1][0], C[1][1]);
return 0;
}
---
#include <stdio.h>
#include <limits.h>
#define V 5
int main() {
int graph[V][V] = {
{0, 10, 0, 30, 100},
{10, 0, 50, 0, 0},
{0, 50, 0, 20, 10},
{30, 0, 20, 0, 60},
{100, 0, 10, 60, 0}
};
dijkstra(graph, 0);
return 0;
}
---
These are the remaining C implementations for questions 6 to 10. Let me know if you
need any modifications or explanations!