Graph isomorphism of two graphs - graph

Today was my exam of discrete structure.
In one question we needed to find whether graphs are isomorphic or not..
Vertices, edges, and degree sequence are same
But in the Graph of G there is the cycle length of 5 aefcba. But in the second graph there is no cycle with the length of 5. According to me they are not isomorphic...
But in my class it is only me who is saying that graphs are not isomorphic...
Am I wrong?
Sorry for my bad english : p

You are correct, but your proof is missing the part where you prove that there is no cycle of length 5 in the second graph.
An easy proof is to show that the second graph is bipartite, while the first graph is not... which also completes your proof, because a bipartite graph cannot have an odd-length cycle.

Related

Implementing BFS on same level vertexes of a graph data structure

I'm trying to understand graphs in data structures and got struck here in understanding. can anyone help in understanding this approach. Graphs allow multiple vertexes to connect to any arbitrary vertex without any constraints. while inserting edges, it is possible the vertex to be connected may be on the same level or at any below levels.
In the above figure, BFS through graphs gives 5,6,7 in one and 5,7,6 in another. There is no constraint to get the same level vertexes on graph. How is this identified?
Please let me know as none of the resources point that differenece. Both 6,7 are unvisited from 5,if one refers to 7 and adds to queue(image-1). BFS will be violated.
EDIT:
In the above BFS Example image we have 5 vertexes and if we start from 5 we can either traverse to 6,7 as adjacent nodes. if we are trying to implement BFS here then we can either add 6 or 7 to queue but 7 is the valid one as it is at the same level. How is this identified?
The two drawings you posted show identical graphs: the same three vertices are connected with the same three edges. Graphs don't have levels. They don't keep track of any type of edge ordering, nor the horizontal or vertical layout of the vertices when the graph is drawn.
A BFS starting from vertex 5 could visit either 6 or 7 next. Either order is a valid BFS traversal.

Finding all possible directed graphs given a number of vertices

Is it possible to find all possible directed graphs given a pair of vertices and the information that an edge exists between them? For example if we know the vertices with edge pairs like
1 2
2 3
1 3
The possible directed graphs will be:
1→2, 2→3, 1→3
1→2, 2→3, 3→1
1→2, 3→2, 1→3
1→2, 3→2, 3→1
2→1, 2→3, 1→3
2→1, 2→3, 3→1
2→1, 3→2, 1→3
2→1, 3→2, 3→1
What data-structure to be used here to work with? What can be the working logic?
I was thinking of using adjacency matrix data structure and compute all possible adjacency matrix. Each adjacency matrix will represent a graph. We can use the graph as and when needed for tasks like checking whether cycle is present or not etc.
Apologies that this is more of a discussion than a programming question, but any help will be appreciated
You could maintain one undirected graph data structure G and work with the knowledge that the existence of an edge (u,v) means that there is only one directed edge in a particular instance of digraph possibility D.
If you want to maintain all possible digraphs separately, you would need 2^m many of them, where m is the number of edges. If the vertices and edges are always the same and only the direction is the invariant, then you could maintain 2^m bit-strings, each of length m. Each bit has a 0 or 1 depending on whether the edge (u,v) it corresponds to is u-->v or v<--u. Use the bit string to give direction to the undirected graph suggested above. You just need to generate all 2^m bit strings. Not very efficient... but you can't do better if you need to work with all possibilities.
You could use the bit string to construct a digraph. But, it would be more memory efficient at least to maintain only one bit-string per 'graph' rather than repeating the entire graph data structure with only directional changes. Record bit strings in a hash table: use each edge as a key and then bit value 0/1 depending on direction. Any graph traversal of one of the many possible digraphs D works on undirected G. Then in constant time you can check for incident (undirected) edges of a vertex, which are outgoing/incoming in D. So traversals can occur just as quickly by maintaining only 1 graph object and 1 bit hash table of size 2^m (rather than 2^m graph objects).

How many Complete Graph present in given undirected Graph?

Is there a known algorithm to find all complete sub-graphs within a graph? I have an undirected, graph and I need to find all complete graphs present in that undirected graph.
Is there an existing algorithm for this?
Finding the number of complete subgraphs in an undirected graph is known as the clique problem. It is not solvable in polynomial time, since the number of complete subgraphs itself might be exponential. Therefore, there is not an algorithm that will solve this for graphs of any size in a reasonable amount of time. However, here is one I found that should work for small graphs:
https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm

complexity of printing all possible paths on a graph

In an undirected, unweighted graph, and I'm trying to print (store in file) all possible connecting paths between given 2 vertices on the graph, not including cycles.
when you consider a complete graph this problem is a NP-complete. because there are "(V-2)!" different paths between 2 vertices.
However,seems it is possible to do it with one of graph traversal (DFS-BFS) algorithm with time complexity of O(|V|+|E|) which is pretty polynomial.
I got confuse about solving a NP-Complete problem in polynomial time?
any idea about what is missing here ?
If you want all possible paths, and the graph has V vertices, and E edges, then the number of paths will be dependent upon the number of connects. Consider a fully connected graph, where every point connects to every other point. Then there are (v-2)! possible paths, right? Well (v-2)! > V+E (much greater).

Sequence of number of vertices in a graph

I want to generate a sequence of the number of vertices in all graphs which each edge has the same number of leaving edges. I dont have to generate the whole sequence. Let's say the first 50 if exists.
I want:
Input: the number of edges leaving each vertex
Output: a sequence of the number of vertices
So far, I have looked at complete graphs. Complete graphs with n vertices always have n-1 edges leaving each vertex. But there are other kinds of graphs that have this property. For example, some polyhedrons, such as snub dodecahedron and truncated icosidodecahedron have this property.
How should I approach my problem?
I think you mean regular graphs:
http://en.wikipedia.org/wiki/Regular_graph
http://mathworld.wolfram.com/RegularGraph.html
I made a regular graph generator which isn't flawless by the way:
once you generate the nodes, say from 1 to n. You want regularity r.
For node 1, make connections to the following nodes until you reach degree r for node 1.
For node 2 you already have degree 1 (because of node 1), you connect again to further nodes until you reach degree r for node 2 too. And this way till the last node.
The flaw is that you can't define an r-regular graph for any number of nodes. The algorithm mentioned doesn't detect that, so some errors may occur. Also, this isn't a random r-regular graph generator, but instead give one possible solution.
I'm not much of an explainer, so please ask if the description lacks somewhere.

Resources