11199A048 - DAA Lab Exercises
11199A048 - DAA Lab Exercises
11199A048 - DAA Lab Exercises
Program code:
#include <bits/stdc++.h>
// Constructor
Item(int value, int weight)
{
this->value=value;
this->weight=weight;
}
};
// Driver code
int main()
{
int W = 50; // Weight of knapsack
Item arr[] = { { 60, 10 }, { 100, 20 }, { 120, 30 } };
// Function call
cout << "Maximum value we can obtain = "
<< fractionalKnapsack(W, arr, n);
return 0;
}
Output:
Program code:
#include <bits/stdc++.h>
using namespace std;
#define V 4
// update minimum
min_path = min(min_path, current_pathweight);
} while (
next_permutation(vertex.begin(), vertex.end()));
return min_path;
}
// Driver Code
int main()
{
// matrix representation of graph
int graph[][V] = { { 0, 10, 15, 20 },
{ 10, 0, 35, 25 },
{ 15, 35, 0, 30 },
{ 20, 25, 30, 0 } };
int s = 0;
cout << travllingSalesmanProblem(graph, s) << endl;
return 0;
}
Output:
Ex:6 IMPLEMENT MINIMUM SPANNING TREE
Program code:
return min_index;
}
// Driver code
int main()
{
/* Let us create the following graph
23
(0)--(1)--(2)
|/\|
6| 8/ \5 |7
|/\|
(3)-------(4)
9 */
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 } };
return 0;
}
Output:
Program code:
#include <limits.h>
#include <stdio.h>
// Number of vertices in the graph
#define V 9
// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
// Initialize min value
int min = INT_MAX, min_index;
return min_index;
}
dijkstra(graph, 0);
return 0;
}
Output:
Program code:
#include <iostream>
#include <limits.h>
#include <queue>
#include <string.h>
using namespace std;
return 0;
}
Output:
Program code:
#include<iostream>
#include <list>
using namespace std;
Graph::Graph(int V)
{
this->V = V;
adj = new list<int>[V];
}
list<int>::iterator i;
g.printVertexCover();
return 0;
}
Output: