Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking whether an edge exists in a Graph

Tags:

julia

What is the preferred method for checking whether an edge exists in a graph in the Graphs.jl package?

Say we have a GenericGraph G and we want to check if an edge a->b is in the Graph. I would like to have something similar to has_edge(G, a, b) but that does not appear to exist.

I am currently using in(a, in_neighbors(b, G)) to check, but that may be quite inefficient.

like image 632
Mageek Avatar asked Nov 18 '14 22:11

Mageek


People also ask

How do you check if an edge is connected in a graph?

We can always find if an undirected is connected or not by finding all reachable vertices from any vertex. If count of reachable vertices is equal to number of vertices in graph, then the graph is connected else not. We can find all reachable vertices either using BFS or DFS.

How do I check if an edge exists in adjacency list?

In an adjacency list each vertex u∈V is associated with a list of adjacent vertices. Given a graph G=(V,E), in order to check if the edge (u,v)∈E you need to check whether v∈adjacent[u]. A node can have at most O(|V|) neighbors, from here the complexity follows.

How do you check if an edge is in a cycle?

1- perform a depth first search starting from u, determine if v is found and a back edge exist along the path to v. 2- perform a depth first search from v, if u is found and back edge exist to u, then there's a cycle that includes both u and v.

What is the time complexity for checking if an edge exists in a graph with n vertices and m edges in an adjacency list?

For a given graph, in order to check for an edge we need to check for vertices adjacent to given vertex. A vertex can have at most O(|V|) neighbours and in worst can we would have to check for every adjacent vertex. Therefore, time complexity is O(|V|) .


1 Answers

As far as I understand it, that is the normal way to check for an edge in a graph. It's not really inefficient either.

like image 110
d0nut Avatar answered Oct 15 '22 00:10

d0nut