I am trying to create a menu driven program to produce a depth first search and breadth first search for a graph. I was able to get it to work for integers but I need it to do the same for characters or strings instead of integers. I keep getting a error zsh:segmentation fault whenever .. I am trying to solve a particular problem but i cannot find any suitable solution. I’ll explain … I have a graph where each node has a numeric value. Starting from a node of my choice, I have to find the path where the sum of the node values is the heaviest. The peculiarity of ..

Recently got an assignment on solving n-queens problem using BFS/DFS. My BFS stops at N=7 and I think it’s understandable but DFS has problem with N=8 and goes on for few minutes. Do you have any suggestions how to speed it up? Also can you recommend what should I learn to speed up my code ..

I’ve been trying to make this program save the vertices that make the cycle in the graph. But I’m kind of a newbie in algorithms and achieving that functionality seems a bit complex when using BFS. The code below successfully finds cycles, but the question is how to modify this code so I can print ..

Error E0028 expression must have a constant, can you tell me how to solve it? int V = 5; vector<int> adj[V]; This is full code: #include<iostream> #include <list> #include <vector> using namespace std; void addEdge(vector<int> adj[], int u, int v) { adj[u].push_back(v); } void BFSUtil(int u, vector<int> adj[], vector<bool>& visited) { list<int> q; visited[u] = ..

#include <bits/stdc++.h> using namespace std; int left_arr, right_arr; void swapping(int root, int k) { queue<int> q; q.push(root); int lvl = 0; while (!q.empty()) { lvl++; int size = q.size(); while (size–) { int p = q.front(); q.pop(); if (lvl % k == 0) swap(left_arr[p], right_arr[p]); if (left_arr[p] != -1) q.push(left_arr[p]); if (right_arr[p] != -1) q.push(right_arr[p]); ..

To find shortest path in undirected weighted graph I was comparing BFS and dijkstra’s algo to understand why we need priority queue. I wrote some code modifying BFS to find the shortest path to all nodes in a given graph. Problem link :- https://practice.geeksforgeeks.org/problems/implementing-dijkstra-set-1-adjacency-matrix/1# The below code got accepted on GeeksForGeeks that I wrote instead ..