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
vote
1 answer

Python igraph cant find edges in an undirected graph

I have this simple code in Python 3 using igraph to return an edge which I have added to an undirected graph. from igraph import * g = Graph() g.add_vertices(3) g.add_edges([(0,1), (1,2)]) # display(plot(g)) edge=g.es.find(_source=1,…
1
vote
0 answers

Modify dijkstra's algorithm with some conditions

Given an undirected graph with costs on edges, find the shortest path, from given node A to B. Let's put it this way: besides the costs and edges we start at time t = 0 and for every node you are given a list with some times that you can't pass…
J. Homer
  • 147
  • 1
  • 11
1
vote
1 answer

Trying to pick the right data-structure

So I want to store all the actors from a production in a graph. So from the input we will read like this: Let N be the number of movies we read, for each movie we read: the name of the movie, on the next line would be the number of the actors (let…
J. Homer
  • 147
  • 1
  • 11
1
vote
0 answers

Check if its a Hamilton cycle, create an undirected graph using python

I need to write a code which tells if a cycle is hamilton or not. First i have two text files: 1.file : First line contains the number of vertices and edges while the rest is a pair of two vertices which are connected.Like 0 1 means there is…
1
vote
1 answer

Finding path having a subpath and has maximum gcd(starting node, ending node)

I got a question in a contest(which is ended weeks ago). The question as I interpreted was -: Given an undirected acyclic graph which is connected by (N-1) edges and N nodes. The graph is guaranteed to be connected. Given two nodes u and v, you…
Brij Raj Kishore
  • 1,595
  • 1
  • 11
  • 24
1
vote
0 answers

Storing an arrayList with in another arrayList ends up with empty Lists

I am using depth first search on an undirected graph to find paths from a starting node to an ending node. All the nodes along the path are stored in an ArrayList. But since there can be multiple paths going from start to end, I decided to store…
1
vote
0 answers

Display all hamiltonian cycles or circuits in an undirected graph

I found this algorithm that shows me just one hamiltonian cycle but I need to print all hamiltonian cycles in an undirected graph. Here's the code that I tried to use: https://www.geeksforgeeks.org/hamiltonian-cycle-backtracking-6/ Could someone…
1
vote
1 answer

Use a set of structs and avoid duplicate structs in a set

I am trying to represent a non-directional graph. I created three structs as shown below. I added operator == and operator < to the Edge struct hoping the set would use it to compare elements. struct Node; /* Forward references to these two types…
Sar
  • 33
  • 7
1
vote
1 answer

Building a connected graph from a triangulation

TL;DR: I have a bunch of tetrahedra and I want to know which are its 4 (or less) neighboring (face-sharing) tetrahedra and I do that by checking the points in 3D that they share. This is slow. I am building a connected graph from a triangulation.…
1
vote
2 answers

Random graph with different degree for each node in R

I have 122 nodes and I want to create a random graph, with node degree being fixed for each node. Is there any way to do it in R? I tried igraph, where I can fix the same degree for all nodes i.e. each of the 122 node will have a degree of 2. But, I…
Priya
  • 65
  • 7
1
vote
3 answers

Undirected graphs with less than n edges

I have a data structure that looks like a graph of rather isolated undirected "subgraphs" and would like to get those subgraphs that have less than N edges, in this case only those with one or two edges. I'm a bit lost here and am not sure how to go…
PedroA
  • 1,803
  • 4
  • 27
  • 50
1
vote
2 answers

Which technique will be used for representation of a very large undirected graph in a computer program for its manipulation?

I'm working with a very large undirected graph (email networks for a company). I’m bit confused about selecting the best and suitable technique of undirected graph of email networks. In that network, the vertices represent email addresses and an…
1
vote
1 answer

Prolog: Get sublists that contain given integer

I'm trying to learn Prolog by solving Advent Of Code puzzles, and have ended up being stuck on a task that I think should be pretty simple. The puzzle in question is this one. The task requires me to find all program IDs (integers) that are…
SindreKjr
  • 249
  • 2
  • 17
1
vote
1 answer

Graphic algorithm, assign proper direction to edge

There is an undirected graph G = (V, E), how can I assign each edge a direction so that every vertex has in-degree at most one in O(V+E) time? There should be 2 conditions: Situation 1. G has no cycle What should I use? BFS or DFS, and…
1
vote
1 answer

How to find all the paths in a undirected graph touching all the nodes of a given set

I have an undirected graph and i'd like to find all the possible paths in it connecting all the nodes of a given set. Is it an NP problem? Is there an algorithm to doing it, or a good way to accomplish it? I don't care about the order by which each…