Questions tagged [undirected-graph]

An undirected graph has edges which have no orientation. It is a mathematical concept.

Definition of an undirected graph.

271 questions
-1
votes
2 answers

Calculate the lowest cost of running several resource collectors on an undirected acyclic graph

We have an undirected acyclic graph where there is only a single path between two connected nodes that may look something like this. Simple guide to the image: Black numbers: Node id's (note that each node contains a resource collector) Resource…
-1
votes
1 answer

What should be the size of the minimum vertex cover set for the below test case?

I am solving a problem for finding the size of the vertex cover for a given graph. Below is the test case for which I am not able to interpret what should be the output: 1 4 1 5 1 2 4 1 2 4 3 4 5 2 1 3 These are the edges of an undirected graph…
Noob_Coder
  • 29
  • 3
-1
votes
1 answer

Determine if the graph is directed or undirected

Can anyone offer some suggestions on how to write a method that returns if a graph is directed or undirected in python? Thanks. class DiGraph : def __init__ ( self ) : self._adj = {} def add_node ( self , u ) : if u…
-1
votes
2 answers

Creating undirected weighted graph from adjancency matrix from a csv

I want to create undirected weighted graph of a given adjacency matrix by reading it from a csv. I can read it from a csv but I don't know how to draw its in graph. This is code for reading file. int main(){ ifstream ip("map.csv"); …
shahid hamdam
  • 751
  • 1
  • 10
  • 24
-1
votes
1 answer

how to check presence of cycle in undirected graph?

#include using namespace std; int n,m; vector adj[51]; int visited[51]; bool flag; void dfs(int i,int parent){ vector::iterator it; for(it =…
-1
votes
1 answer

Why my Dijkstra's algorithm implementation in Java for undirected graph doesn't work?

My implementation for directed graph works fine. It's a "lazy" version because it uses simple priority queues instead of indexed ones. I changed the code to get a solution for undirected graphs but it doesn't work. dijkstra(int s) is a method of a…
-1
votes
1 answer

ArrayIndexOutOfBoundsException on generating maze graph with depth first search

I created a program that solves a maze that reads a text file input. I managed to solve it using Depth-first Search and the result was fine on small mazes like this: 11 3 2 3 0 3 1 4 5 4 5 7 6 7 7 8 8 9 9 10 0 5 Everything was fine solving small…
-1
votes
1 answer

Which algorithm+representation should I use for finding minimum path distance in a huge sparse undirected graph?

I need to find the minimum distance between two nodes in a undirected graph, here are some details The graph is undirected and huge(no of nodes is in order of 100,000) The graph is sparse, no of edges is less than no of nodes I am not interested in…
-2
votes
2 answers

Find a tuple in a list of tuples and add if not present

There is an undirected graph with a list of tuples where each element is a tuple in the form of (id1,id2). I have to find whether a new (s,t) is present in the list of tuples which contains all the edges and add the tuple if it is not present. edges…
rashf
  • 27
  • 5
-2
votes
2 answers

How to shrink a Map in Java after deleting one of its elements (objects)?

Let's assume I'm given a map represented as {[A, 0], [B, 1] [C, 2], [D, 3], [E, 4], [F, 5], [G, 6]} and were to delete one of its elements, i.e [E, 4], then my new map would become {[A, 0], [B, 1] [C, 2], [D, 3], [F, 5], [G, 6]}. How would I resize…
-2
votes
1 answer

Error in detecting cycle in undirected graph code

#include using namespace std; bool iscycle(list *adj,bool *visited,int i,int parent){ visited[i] = true; for(auto j : adj[i]){ if(!visited[j]) if(iscycle(adj,visited,j,i)) return true; …
-2
votes
1 answer

Matrix formalism NxN adjacency matrix

Let A be the NxN adjacency matrix of an undirected unweighted network, without self-loops. Let 1 be a column vector of N elements, all equal to 1. In other words 1 = (1, 1, ..., 1)T , where the superscript T indicates the transpose operation. Use…
-2
votes
2 answers

Shortest path of undirected graph with an extra weight edge provided

We are provided with an undirected graph, source node, destination node and the weight of an extra edge which you can use to connect any two nodes which were not connected earlier. You have to find the minimum weight of the path possible between the…
-2
votes
1 answer

DFS on undirected graph

I have an exercise for university where I have to write a DFS algorithm to run on an undirected graph. I also have to make the program sum the values of all nodes show the order in which the nodes were visited. Here is the given structure: #include…
Bruncky
  • 117
  • 12
-3
votes
1 answer

String Searching Algorithm that uses a graph ? C++

Code Instructions Hey guys. Above is a coding project I have been assigned. Im reading the instructions and am completely lost because I've never learned how to code an undirected graph? Not sure how my professor expects us to do this but I was…
1 2 3
18
19