Objective: LAB-1: Implementation of Quick Sort and Merge Sort 1.1 Quick Sort
Objective: LAB-1: Implementation of Quick Sort and Merge Sort 1.1 Quick Sort
Objective: LAB-1: Implementation of Quick Sort and Merge Sort 1.1 Quick Sort
#include <stdio.h>
}
int main() {
int A[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(A) / sizeof(A[0]);
quickSort(A, 0, n - 1);
return 0;
}
Output
1.2 Merge Sort
#include <stdio.h>
int main() {
int A[] = {9, 4, 5, 10, 12, 2};
int n = sizeof(A) / sizeof(A[0]);
MergeSort(A, 0, n - 1);
return 0;
}
Output
LAB-2
Objective: Implementation of Linear-Time Sorting Algorithm
#include <stdio.h>
int main() {
int A[] = {170, 45, 75, 90, 802, 24, 2, 66};
int n = sizeof(A) / sizeof(A[0]);
radixSort(A, n);
return 0;
}
Output
1.2 Count Sort
#include <stdio.h>
countSort(A, n);
return 0;
}
Output
1.3. Bucket Sort
#include <stdio.h>
#include <stdlib.h>
#define BUCKET_COUNT 10
int index = 0;
for (int i = 0; i < BUCKET_COUNT; i++) {
for (int j = 0; j < bucketSizes[i]; j++) {
A[index++] = buckets[i][j];
}
}
}
bucketSort(A, n);
return 0;
}
Output
LAB - 3
#include <stdio.h>
#include <stdlib.h>
int main() {
insert(10);
insert(20);
insert(30);
insert(15);
printf("Inorder Traversal: ");
inorder(root);
return 0;
}
Output:
LAB-4
Objective-Implementation of Binomial Heap Operations
#include <stdio.h>
#include <stdlib.h>
struct Node {
int key, degree;
struct Node *parent, *child, *sibling;
};
return newHeap;
}
while (next) {
if ((curr->degree != next->degree) || (next->sibling && next->sibling->degree == curr-
>degree)) {
prev = curr;
curr = next;
} else if (curr->key <= next->key) {
curr->sibling = next->sibling;
curr = mergeBinomialTrees(curr, next);
} else {
if (prev) prev->sibling = next;
else heap = next;
next = mergeBinomialTrees(next, curr);
curr = next;
}
next = curr->sibling;
if (curr->key < next->key) {
linkTrees(next, curr);
curr = next;
} else {
linkTrees(curr, next);
}
}
next = curr->sibling;
}
return h;
}
void insert(BinomialHeap* heap, int key) {
BinomialHeap* temp = createHeap();
temp->head = createNode(key);
heap = unionHeaps(heap, temp);
}
Output
LAB-5
#include <stdio.h>
int fibonacci(int n) {
int fib[n + 1];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i <= n; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
return fib[n];
}
int main() {
int n = 10;
printf("Fibonacci of %d is %d\n", n, fibonacci(n));
return 0;
}
Output
LAB-6
#include <stdio.h>
struct Item {
int weight;
int value;
};
int main() {
struct Item items[] = {{10, 60}, {20, 100}, {30, 120}};
int capacity = 50;
int n = sizeof(items) / sizeof(items[0]);
fractionalKnapsack(items, n, capacity);
return 0;
}
Output
LAB-7
#include <stdio.h>
#include <limits.h>
#define V 5
key[0] = 0;
parent[0] = -1;
printMST(parent, graph);
}
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;
}
Output
LAB-8
#include <stdio.h>
#include <limits.h>
#define V 5
dist[src] = 0;
dijkstra(graph, 0);
return 0;
}
Output
LAB-9
#include <stdio.h>
#define V 4
#define INF 99999
int main() {
int graph[V][V] = {{0, 3, INF, 7},
{8, 0, 2, INF},
{5, INF, 0, 1},
{2, INF, INF, 0}};
floydWarshall(graph);
return 0;
}
Output
LAB-10
#include <stdio.h>
#include <string.h>
if (j == patternLength)
printf("Pattern found at index %d\n", i);
}
}
int main() {
char text[] = "ABABDABACDABABCABAB";
char pattern[] = "ABABCABAB";
naiveStringMatching(text, pattern);
return 0;
}
Output