All possible possible directed graphs in V={1,2,3} - graph

I got this exercise :
Give an example of three different directed graphs on V = {1, 2, 3}
where the edges (1, 2) and (1, 3) exist. Write both the adjacency-list and adjacency-
matrix representation for each.
I find only this two:
G = {(1,2), (1,3)}
G = {(1,2), (1,3), (2,3)}
What I miss? Something like that is valid: G = {(1,2), (1,3), (3,2)} ?

It's a directed graph, which means all links are one-way. If you want to be able to go from 1 to 2 and from 2 to 1, you need two links, (1,2) and (2,1) - that's part of the definition of a directed graph.
With that, enumerate all possible links for a graph of 3 vertexes:
(1,2)
(2,1)
(1,3)
...
Once you enumerate all possible links in such a graph, you can pick and choose unique sets of those links to make into multiple graphs, subject to the constraints given to you by the exercise.
For instance, here are a couple graphs:
{(1,2)}
{(2,1)}
{(1,3)}
{(3,1)}
{(3,2), (2,1), (1,3)}
...
You already have two out of three requested answers and you need a third graph to complete the exercise. You need to give answers that include two provided links. Why not give as an answer a graph that has every link in it? A graph of every link must contain the two requested links, right?

Related

Find the maximum number of distinct graphs

The question is: How many distinct non-oriented graphs, with 6 nodes, numbered from 1 to 6, can be constructed so that node 2 has degree 1. Two graphs are distinct if their adjacency matrices are different.
I know some notions about graphs and I thought that I would have to find out the number of distinct non-oriented graphs that can be built with 5 nodes and then multiply that by the number 5.
The problem is that I can't figure it out because I don't really understand the notion of degree in a graph.
I would appreciate your help. Thanks!!
Taking into consideration again, some aspects of this problem, I have reached a conclusion.
There are 5 nodes that can form the distinct graphs, because 1, 3, 4, 5, 6 are, possibly, the adjacent nodes of node 2.
With these five nodes, there can be 2 ^ 10 distinct unoriented graphs, which is 2 ^ (5*2).The logic is that 5 is the number of nodes that are adjacent to node 2, and 2 is the number of connections that each node has, because the graph is undirected. And this number represents the graphs that can be built, in order to respect the condition.
At the end, the only operation to be done is to multiply (2 ^ 10) * 5.
So all the graphs should have 6 nodes, there is no difference between the number of nodes in the number of graphs that are possible.
The notion of symmetry of a graph usually refers to a graph that reflects the behaviour of a mathematical function; in this context, of mathematical functions, it is True that a graph can be symmetric with respect to a line.
https://www.maplesoft.com/support/help/maple/view.aspx?path=MathApps/SymmetriesOfAGraph

Color vertices in igraph R or C

I have a network file for two groups, A and B, and I am plotting the network in R using igraph, and I would like the vertices to be colored depending on their group. The vertices are orderered, i.e. 1-50 are group A and 51-100 are group B. In the others forums a similiar question was asked however in those cases the coloring could be made depending on vertex attributes. In my case the vertices do not have attributes (except for their order). This is is how far I got:
g<- read.graph("AdjacencyMatrix.net", format = c("pajek"))
V(g)$color <- ifelse(XXXXX[V(g), 2] == 1, XXXXX<=50, XXXXX>50)
where XXXXX stands for the id or number of the vertex in the list. Is there a way to do this?

Find length of longest trail in directed unweighted graph

I have a directed, unweighted, possibly cyclic graph that can contain loops and multiple duplicate edges (i.e. two edges from node 1 to node 2).
I would now like to find the length of the longest trail in this graph, i.e. the longest path that:
- uses no edge twice (but if there are multiple edges from node 1 to node 2, it can use every one of them)
- possibly visits nodes several time (i.e. it does not have to be a simple path)
In particular, is this problem NP-hard? I know that the longest simple path is NP-hard (reducing Hamiltonian Path to it) and the longest trail with edge reusal is in P (Bellman ford with weight -1 on every edge). However, with this problem, I am not quite sure and I could not find good information on it.
Although I am not completely sure, I think that this problem is NP-hard. As I understand, your question arises due to multiple edges between nodes. The graphs that has multiple edges between same nodes can be expanded to larger graphs with no multiple edges between them. Thus, a graph with multiple edges between same nodes has no difference than a graph without multiple edges.
Let me walkthrough a simple example to explain:
Let there be a graph with 3 nodes (A,B,C) and 5 edges between them (A to B, A to B, B to A, B to C, C to A)
This graph can be expanded and shown with 5 nodes and 7 edges.
Lets expand the node A to 3 different nodes (A1, A2, A3). When we adjust the edges according to previous edges, there exists 7 edges(A1 to B, A2 to B, B to A3, B to C, C to A1, C to A2, C to A3)
As a result, now we have a graph without multiple edges and can be evaluated with the help of Hamiltonian and Bellman Ford.
Hope I've at least cleared the problem a bit.

Search common subgraph between two graphs

I have two graphs G, H labeled and I want to extract all common subgraph of two graphs, I got to a part that is:
1 - extract all the nodes that are in common, but I'm stuck on the part that includes:
2 - Step 1: Take the First vertex and store it in a set P = {first element} (which will be the set of all common subgraph), and go to 2nd if it is adjacent to the first of the two P graph G and H, we add it, and so on, but I do not know how to do it when i have more than 2
That is a NP-complete problem. See http://en.wikipedia.org/wiki/Subgraph_isomorphism_problem

Partitioning adjacency matrix of bipartite graph

Lets say I have a graph G with its adjacency matrix A. I know that G is bipartite.
How can I split the vertices in G into the two sets that always form a bipartite graph?
Thanks!
Declare an array which of size equal to the number of vertices, setting each element to 0 initially. Then perform a depth-first search through the graph, recording the "level number" that you are on as you go. This starts at 1, and alternates between 1 and 2 with each edge traversed. For every vertex reached, assign the current level to the corresponding entry of which, and (if it was previously 0) recurse to process its children. Afterwards, all elements of which will be either 1 or 2, and which[i] indicates which set vertex i belongs to.
Intuitively, you can imagine that each traversal from parent to child in the DFS takes you "down" a level, and each traversal back takes you back "up". By the bipartite property, all vertices on even levels can be connected only to vertices on odd levels and vice versa, so labelling nodes "even" or "odd" suffices to partition them into the two sets.
If your graph contains more than one component, you will of course need a separate DFS for each component.

Resources