Lab9 193
Lab9 193
Sem-Sec-Group: 5 C 2
Dijkstra Algorithm :
Source Code :
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
return minVertex;
}
int main() {
int V, E, source;
cout << "Enter the number of vertices: ";
cin >> V;
cout << "Enter the number of edges: ";
cin >> E;
cout << "Enter the edges (source, destination, weight):" << endl;
for (int i = 0; i < E; ++i) {
int u, v, w;
cin >> u >> v >> w;
graph[u][v] = w;
graph[v][u] = w; // Uncomment this line for undirected graph
}
dijkstra(graph, source);
return 0;
}
Output:
AIM: Write a program to implement Greedy Knapsack Problem.
Source Code :
#include <iostream>
#include <vector>
#include <algorithm>
// Constructor
Item(int v, int w) : value(v), weight(w) {}
};
return totalValue;
}
int main() {
int n, W;
vector<Item> items;
cout << "Enter the value and weight of each item:" << endl;
for (int i = 0; i < n; ++i) {
int value, weight;
cin >> value >> weight;
items.emplace_back(value, weight);
}
return 0;
}
Output: