Shivam final daa lab file.pdf
Shivam final daa lab file.pdf
PRADESH, GWALIOR
PRACTICAL FILE OF
SEMESTER – 5th
#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 70, 80, 90, 11, 59};
int n = sizeof(arr) / sizeof(arr[0]);
cout<<"Shivam Rathore"<<endl;
quickSort(arr, 0, n - 1);
return 0;
}
#include <iostream>
using namespace std;
} else {
arr[k] = R[j];
j++;
}
k++;
}
#include <iostream>
#include <vector>
using namespace std;
class Queue {
public:
int size;
int f;
int r;
int* arr;
Queue(int s) {
size = s;
f = r = 0;
arr = new int[size];
}
bool isEmpty() {
return r == f;
}
bool isFull() {
return r == size - 1;
}
#include <bits/stdc++.h>
using namespace std;
return true;
}
if (col >= n)
return true;
bool solveNQ(int n) {
vector<vector<int>> board(n, vector<int>(n, 0));
if (solveNQUtil(board, 0) == false) {
cout << "Solution does not exist";
return false;
}
int main() {
int n = 4;
solveNQ(n);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
bool flag = 0;
int set[n];
cout << "Enter the elements of the set: ";
for (int i = 0; i < n; i++) {
cin >> set[i];
}
vector<int> subset;
cout << "Subsets with sum equal to " << targetSum << ":" << endl;
PrintSubsetSum(0, n, set, targetSum, subset);
if (!flag) {
cout << "There is no such subset";
}
return 0;
}
#define V 5
bool isSafe(int v, const vector<vector<int>>& graph, const vector<int>& path, int pos) {
if (graph[path[pos - 1]][v] == 0)
return false;
if (pos == V) {
if (graph[path[pos - 1]][path[0]] == 1)
return true;
return false;
}
path[pos] = -1;
}
}
return false;
}
bool hamCycle(const vector<vector<int>>& graph) {
vector<int> path(V, -1);
path[0] = 0;
hamCycle(graph);
return 0;
}
#include <algorithm>
#include <iostream>
using namespace std;
struct Job {
char id;
int dead;
int profit;
};
bool comparison(Job a, Job b) {
return (a.profit > b.profit);
}
int result[n];
bool slot[n];
int main() {
int n;
cout << "Enter the number of jobs: ";
cin >> n;
cout<<"Shivam Rathore"<<endl;
Job arr[n];
for (int i = 0; i < n; i++) {
cout << "Enter job id, deadline, and profit for job " << i + 1 << ": ";
cin >> arr[i].id >> arr[i].dead >> arr[i].profit;
}
return 0;
}
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
while (!pq.empty()) {
int u = pq.top().second;
int d = pq.top().first;
pq.pop();
if (d > dist[u]) {
continue;
}
return dist;
}
int main() {
int V, E;
cout << "Enter the number of vertices: ";
cin >> V;
vector<vector<pii>> adj(V);
cout << "Enter the edges (format: u v weight), where u and v are vertex indices (0
to " << V-1 << "):" << endl;
for (int i = 0; i < E; ++i) {
int u, v, weight;
cin >> u >> v >> weight;
adj[u].push_back({v, weight});
adj[v].push_back({u, weight});
}
int start;
cout << "Enter the starting node: ";
cin >> start;
cout << "\nShortest distances from node " << start << ":\n";
for (int i = 0; i < V; ++i) {
if (shortestPaths[i] == INT_MAX) {
cout << "Distance to " << i << " is INF\n";
} else {
cout << "Distance to " << i << " is " << shortestPaths[i] << "\n";
}
}
return 0;
}
#include <iostream>
#include <vector>
#include <climits>
#include <queue>
using namespace std;
key[0] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
inMST[u] = true;
int main() {
int V, E;
cout<<"Shivam Rathore"<<endl;
vector<vector<pii>> adj(V);
cout << "Enter the edges (u v weight), where u and v are vertex indices (0 to " << V-1
<< "):\n";
for (int i = 0; i < E; ++i) {
int u, v, weight;
cin >> u >> v >> weight;
adj[u].push_back({v, weight});
adj[v].push_back({u, weight});
}
primMST(V, adj);
return 0;
}
struct Edge {
int u, v, weight;
bool operator<(const Edge& e) {
return weight < e.weight;
}
};
class DisjointSet {
public:
vector<int> parent, rank;
DisjointSet(int n) {
parent.resize(n);
rank.resize(n, 0);
for (int i = 0; i < n; i++) {
parent[i] = i;
}
}
int find(int x) {
if (parent[x] != x) {
parent[x] = find(parent[x]);
}
return parent[x];
}
if (rootX != rootY) {
if (rank[rootX] > rank[rootY]) {
parent[rootY] = rootX;
} else if (rank[rootX] < rank[rootY]) {
parent[rootX] = rootY;
} else {
parent[rootY] = rootX;
rank[rootX]++;
}
}
}
};
sort(edges.begin(), edges.end());
if (ds.find(u) != ds.find(v)) {
mst.push_back(edge);
ds.unionSets(u, v);
}
}
return mst;
}
SHIVAM RATHORE 28 A60205222086
int main() {
cout<<"Shivam Rathore"<<endl;
int n, m;
cout << "Enter number of vertices: ";
cin >> n;
cout << "Enter number of edges: ";
cin >> m;
vector<Edge> edges(m);
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
return dp[n][W];
}
int main() {
cout<<"Shivam Rathore"<<endl;
int n, W;
cout << "The maximum value that can be obtained: " << maxValue << endl;
return 0;
}