A graph with maximum number of strongly connected components - graph

Create a directed graph with 6 nodes (say) such that it has maximum number of strongly connected components.
For example, take complete graph with 4 nodes with all edges connected. This is graph has only 1 strongly connected component, i.e entire graph is a single component.
The objective is to maximise the number of components.

Your question does not make sense as posted.
Best guess: you want to create a new graph with a given number of nodes that will have the maximum number of strongly connected components. Edges can be added between any pairs of nodes.
The smallest strongly component is a pair of nodes with an edge going in each direction between them.
So the maximum number of components in a graph with N nodes will be N / 2
e.g. a 4 node graph with two components has edges between
1 2
2 1
3 4
4 3
1 3

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

How to check if a path exists between two nodes of length exactly x in an undirected graph?

An undirected graph is given (as an adjacency list or incidence matrix). For multiple queries, check if a path of length exactly x exists between two nodes. Same nodes can be visited more than once.
I know that for single queries it's easy to check for this, simply by raising the incidence matrix to the power x (number of steps) and checking if the value at [first node][second node] is greater that 0. This takes too long, and for bigger matrices it takes too much memory. Even more so for multiple queries.
How can I solve this problem using as little space and time as possible?
Example:
Graph
Queries:
Is it possible to reach 3 from 2 in 1 step? yes
Is it possible to reach 4 from 1 in 1 step? no
Is it possible to reach 5 from 5 in 8 steps? yes
Is it possible to reach 8 from 1 in 10 steps? no
Thank you in advance.

Longest path in adjacency matrix in R

Hypothetical scenario to have a descriptive example: I've a model consisting of 10 parts (vertices) to be put together. Each part can be connected to others (edges) as defined by a connection table.
There's a shortest.paths function in igraph. However here the aim is to find a way to calculate the longest path in the adjacency matrix. Resulting in a path using as many parts as possible, ideally all, so no part of the model is left alone in the end. MWE as follows:
library(igraph)
connections <- read.table(text="A B
1 2
1 7
1 9
1 10
2 7
2 9
2 10
3 1
3 7
3 9
3 10
4 1
4 6
4 7
7 5
7 9
7 10
8 9
8 10
9 10", header=TRUE)
adj <- get.adjacency(graph.edgelist(as.matrix(connections), directed=FALSE))
g1 <- graph_from_adjacency_matrix(adj, weighted=TRUE, mode="undirected")
plot(g1)
Edit:
The result should be something like: for instance if the first part of the model is 8 it could be combined with 9 or 10. Let's say 10 is selected next part can be either 1,2,7 or 9. If 9 is selected as next the follow up could be 1,2,3,7 or 8. If then 8 is selected the model would be finished as part 10 is already in use. The question then would be how to find a way/path to put together as many parts as possible, ideally all of them. The latter would be possible only by starting with 6 or 5.
There are cycles in your graphs, and I don't think you have stated that we cannot use the same vertex (part) more than once: and in this case the longest path might be infinitely long as you can traverse the cycle infinitely many times and then proceed to your destination.
As per your edit, I think this is not allowed. You can use dynamic programming for this I hope. You can start with DFS like algorithm and mark all the vertex except starting as unvisited. Then apply recursion to choose maximum between the longest paths from all the possible vertex we can reach (except which are already visited) from that given vertex.
It is an NP-hard problem, so you would have to check all the possible paths!
You can see: https://en.wikipedia.org/wiki/Longest_path_problem . You will have modify the algorithm to work in graphs with cycle by adding, as stated earlier, a flag to tell which vertices are already visited.
Tell me if i get it right, you are trying to find a path, that touch the maximum number of nodes?
If that so this is basically an instance of the Hamiltonian path problem, I would say an easier version of it if you can pass on a node more than 1 time.
You can try to watch that algorithm.
to respect you edit maybe, you can try to see the graphs search algorithms, you can find something here, however be advise that this type of algorithms are quite heavy on the memory complexity side.

How to find polygons in a given set of points and edges?

Consider the following problem:
Given N points in plane and M line segments connecting them, find all polygons (convex or concave) that do not contain any other polygons inside.
For instance:
There are 5 polygons founded:
1 - 2 - 5 - 6
2 - 3 - 5
3 - 4 - 5
7 - 8 - 9
10 - 13 - 20 - 12 - 11
How can I identify these polygons and there corresponding vertices and edges? And what is the fastest solution for this?
Build graph with segment ends as vertices and segments as edges, then find cycles using DFS.
Note that the same edges might belong to multiple cycles (polygons) like your 2-5 and there might be many variants to select cycles. To exclude ambiguity, you can build fundamental set of cycles
Edit. As weston noticed in comments, resulted polygons might contains others. So sketch of more geometric approach:
Build lists of adjacency for graph.
Sort edges in ever list by polar angle.
Choose the most bottom vertex A.
If it's degree is 0, remove vertex, if 1, remove vertex and edge.
Otherwise get edge E with the smallest angle from this vertex.
Walk to pair vertex B.
Choose the most left edge F from B.
Move along to F edge into C.
If dead end, remove F and vertex C and return to B.
Repeat moving using left-hand rule until meet vertex A or dead end vertex.
In the walk process remove edges outgoing from vertices of degree 2 or mark them as used.

5 values for a face in PLY files?

I was just barely introduced to .ply files and I don't understand how they work. The vertex list has only 3 values for each vertex: x,y,z. But each face has 5 values and I don't know what those 5 values mean. I just need a little explanation. Thanks!
This simply means that the face has 5 sides or 5 vertices and each vertex's position is specified in space by the 3 values x,y,z.
The above answer is not exactly right to my knowledge.
The first value is the number of vertices which define the face, in your case it should be 4, as there are only 4 numbers left. The four other numbers are indices of the vertices. Like often in computer science, the index of the first vertex is 0, not 1.
Some programs though support only triangular meshes, and faces with more than 3 edges are not supported.
Furthermore, if you use a visualization program which adds light and other rendering stuff, the face 3 0 1 2 is not the same as 3 0 2 1 as the triangle has another orientation.

Resources