DAA Practical File
DAA Practical File
Course Objective
Course Outcomes
2|Pa ge
Syllabus
3|Pa ge
int main(){
int z[2][2];
int i, j;
int x[2][2] = {
{12, 34},
{22, 10}
};
printf("\n");
printf("%d\t", x[i][j]);
printf("\n");
printf("%d\t", y[i][j]);
z[0][1] = m3 + m5;
z[1][0] = m2 + m4;
z[1][1] = m1 - m2 + m3 + m6;
printf("\n");
printf("%d\t", z[i][j]);
return 0;
}
5|Pa ge
OUTPUT
The first matrix is :
12 34
22 10
3 4
2 1
104 82
86 98
6|Pa ge
int i = 0, j = 0;
int k = left;
arr[k] = L[i];
i++;
} else{
arr[k] = R[j];
j++;
k++;
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
printf("\n");
int main(){
printArray(arr, arr_size);
mergeSort(arr, 0 , arr_size-1);
printArray(arr, arr_size);
return 0;
}
8|Pa ge
OUTPUT
Given array is
12 11 13 5 6 7
Sorted array is
5 6 7 11 12 13
9|Pa ge
int t = *a;
*a = *b;
*b = t;
i++;
swap(&arr[i], &arr[j]);
swap(&arr[i+1], &arr[high]);
return(i + 1);
printf("\n");
}
10 | P a g e
int main(){
printArray(arr, n);
quickSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
}
11 | P a g e
OUTPUT
Given array is
10 2 43 6 34 1 4
Sorted array is
1 2 4 6 10 34 43
12 | P a g e
#include <stdlib.h>
struct Item {
int value;
int weight;
};
return 0;
int curWeight = 0;
curWeight += arr[i].weight;
finalValue += arr[i].value;
} else {
break;
return finalValue;
int main() {
13 | P a g e
int W = 50;
return 0;
}
14 | P a g e
OUTPUT
Maximum value in Knapsack = 240.00
15 | P a g e
#include <stdlib.h>
struct Job {
char id;
int deadline;
int profit;
};
int result[n];
int slot[n];
slot[i] = 0;
if (slot[j] == 0) {
result[j] = i;
slot[j] = 1;
break;
if (slot[i])
}
16 | P a g e
printf("\n");
int main() {
struct Job arr[] = {{'a', 2, 100}, {'b', 1, 19}, {'c', 2, 27}, {'d', 1, 25}, {'e', 3, 15}};
jobSequencingWithDeadline(arr, n);
return 0;
}
17 | P a g e
OUTPUT
Following is the sequence of jobs that maximizes profit:
cae
18 | P a g e
#include <stdlib.h>
struct Edge {
};
struct Graph {
int V, E;
};
struct Subset {
int parent;
int rank;
};
graph->V = V;
graph->E = E;
return graph;
if (subsets[i].parent != i)
return subsets[i].parent;
subsets[xroot].parent = yroot;
subsets[yroot].parent = xroot;
else {
subsets[yroot].parent = xroot;
subsets[xroot].rank++;
int V = graph->V;
int e = 0;
int i = 0;
subsets[v].parent = v;
subsets[v].rank = 0;
if (x != y) {
result[e++] = next_edge;
20 | P a g e
Union(subsets, x, y);
return;
int main() {
int V = 4;
int E = 5;
graph->edge[0].src = 0;
graph->edge[0].dest = 1;
graph->edge[0].weight = 10;
graph->edge[1].src = 0;
graph->edge[1].dest = 2;
graph->edge[1].weight = 6;
graph->edge[2].src = 0;
graph->edge[2].dest = 3;
graph->edge[2].weight = 5;
graph->edge[3].src = 1;
graph->edge[3].dest = 3;
graph->edge[3].weight = 15;
graph->edge[4].src = 2;
graph->edge[4].dest = 3;
graph->edge[4].weight = 4;
KruskalMST(graph);
return 0;
}
21 | P a g e
OUTPUT
Following are the edges in the constructed MST
2 -- 3 == 4
22 | P a g e
• Prims Algorithm
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#define V 5
return min_index;
printf("Edge \tWeight\n");
int parent[V];
int key[V];
bool mstSet[V];
key[0] = 0;
parent[0] = -1;
mstSet[u] = true;
printMST(parent, graph);
int main() {
{2, 0, 3, 8, 5},
{0, 3, 0, 0, 7},
{6, 8, 0, 0, 9},
{0, 5, 7, 9, 0}};
primMST(graph);
return 0;
}
24 | P a g e
OUTPUT
Edge Weight
0-1 2
1-2 3
0-3 6
1-4 5
0—3==5
0—1==10