Number of complete subgraphs in a given undirected graph - algorithm

What is the best approach to find the number of complete sub-graphs with maximum number of nodes possible, given an undirected graph?
PS: By complete I meant that every node is connected to every other node with an unique edge.

You are talking about Clique Problem, this is a classical computer science problem, it is NP Complete. Which means that it doesn't have any solution to it, which could run on today's computers in polynomial time.
Although, approximation algorithms exist to give a solution, they are weak.

Related

Finding strongly connected subgraph that contains no negative cycles

Is there an algorithm that solves the following decision problem:
Given a strongly connected weighted directed graph G, defined by its transition matrix, is there a strongly connected spanning subgraph of G that has no negative cycles?
A strongly connected spanning subgraph of G is a strongly connected subgraph of G that shares the same vertexes with G. You can look to this paper for the definition of strongly connected spanning subgraph. In this paper they present an approximation for the minimum strongly connected subgraph problem.
A naive approach to this problem is to find a negative cycle of the graph using the Ford-Bellman or Floyd-Warshall algorithm, deleting an edge from this cycle, and repeating while the graph is still strongly connected. But this naive approach has poor time complexity because we will potentially run the Ford-bellman algorithm and check for strong connectivity many times -- moreover I am unable to prove if this algorithm is correct in all instances.
I'm hoping to find experts here who can tell me if this decision problem can be solved in a polynomial time and what algorithm does so. Many thanks in advance.
Here is a naive solution that has a reasonable chance of finding a strongly connecting spanning subgraph with no negative cycles in polynomial time. But is emphatically not guaranteed to find one.
Turn all weights to their negatives. Now use Ford-Bellman or Floyd-Warshall to find a negative cycle. This is actually a positive cycle in the original graph.
Now we pick one vertex in the cycle, and contract the other vertices to it.
Edges that connect to/from removed vertices are replaced by ones representing traveling along that edge and around the cycle to the one we keep. If you wind up with multiple edges between two vertices, only keep the best one.
Repeat the exercise on the new, smaller, graph.
This algorithm runs in guaranteed polynomial time (each iteration runs in polynomial time and removes at least one vertex). If it manages to reduce your graph to a point, then you just walk the process backwards and find that you have in fact found a strongly connected spanning graph with no negative cycles.
However if it fails to do so, there is no guarantee that there isn't one. You just didn't find it.
(I suspect that a guaranteed algorithm will be NP-complete.)
This problem is NP hard in general, this can be proven by reducing Hamiltonian cycle into it.

Minimal spanning tree with K extra node

Assume we're given a graph on a 2D-plane with n nodes and edge between each pair of nodes, having a weight equal to a euclidean distance. The initial problem is to find MST of this graph and it's quite clear how to solve that using Prim's or Kruskal's algorithm.
Now let's say we have k extra nodes, which we can place in any integer point on our 2D-plane. The problem is to find locations for these nodes so as new graph has the smallest possible MST, if it is not necessary to use all of these extra nodes.
It is obviously impossible to find the exact solution (in poly-time), but the goal is to find the best approximate one (which can be found within 1 sec). Maybe you can come up with some hints of the most efficient way of going throw possible solutions, or provide with some articles, where the similar problem is covered.
It is very interesting problem which you are working on. You have many options to attack this problem. The best known heuristics in such situation are - Genetic Algorithms, Particle Swarm Optimization, Differential Evolution and many others of this kind.
What is nice for such kind of heuristics is that you can limit their execution to a certain amount of time (let say 1 second). If it was my task to do I would try first Genetic Algorithms.
You could try with a greedy algorithm, try the longest edges in the MST, potentially these could give the largest savings.
Select the longest edge, now get the potential edge from each vertex that are closed in angle to the chosen one, from each side.
from these select the best Steiner point.
Fix the MST ...
repeat until 1 sec is gone.
The challenge is what to do if one of the vertexes is itself a Steiner point.

Finding fully connected components?

I'm not sure if I'm using the right term here, but for fully connected components I mean there's an (undirected) edge between every pair of vertices in a component, and no additional vertices can be included without breaking this property.
There're a number algorithms for finding strongly connected components in a graph though (for example Tarjan's algorithm), is there an algorithm for finding such "fully connected components"?
What you are looking for is a list of all the maximal cliques of the graph. It's also called the clique problem. No known polynomial time solution exists for a generic undirected graph.
Most versions of the clique problem are hard. The clique decision problem is NP-complete (one of Karp's 21 NP-complete problems). The problem of finding the maximum clique is both fixed-parameter intractable and hard to approximate. And, listing all maximal cliques may require exponential time as there exist graphs with exponentially many maximal cliques. Therefore, much of the theory about the clique problem is devoted to identifying special types of graph that admit more efficient algorithms, or to establishing the computational difficulty of the general problem in various models of computation.
-https://en.wikipedia.org/wiki/Clique_problem
I was also looking at the same question.
https://en.wikipedia.org/wiki/Bron-Kerbosch_algorithm This turns out to be an algorithm to list it, however, it's not fast. If your graph is sparse, you may want to use the vertex ordering version of the algorithm:
For sparse graphs, tighter bounds are possible. In particular the vertex-ordering version of the Bron–Kerbosch algorithm can be made to run in time O(dn3d/3), where d is the degeneracy of the graph, a measure of its sparseness. There exist d-degenerate graphs for which the total number of maximal cliques is (n − d)3d/3, so this bound is close to tight.[6]

Shortest path to connect n points

I have n points and I need to connect all of them minimizing the final distance. The image above represents an algorithm that in each node it connects to the nearest one but the final output might be really of.
I've been searching a lot, I know some pathfinding algos but unaware of one that solves exactly this case. I found a question on Math Stackexchange but the answer is not providing any algorithm - https://math.stackexchange.com/a/581844/156584.
Is there any algorithm that solves exactly this problem? Otherwise I can bruteforce it.
Edit: Some clarification regarding the result I'm expecting: each node can be connected to 2 other nodes, creating a continuous path (like taking a pen and without ever lifting it, connect the nodes minimizing the final distance). I don't want to create a cycle (that being the travelling salesman problem).
PS: this question can also be translated to "complete graph with n vertices, and wanting to choose the set of edges such that the graph is connected, but the sum of the edge weights is minimized"
This problem is known as the shortest Hamiltonian path problem and it is NP-hard. So if the number of points is small, you can use backtracking or dynamic programming to find an optimal solution. If the number of points is large, you can use heuristics and/or approximations to obtain a relatively good answer(it is not always possible to find the best one in this case, though).

Getting Paths that cover all the nodes and Start and End at Special Nodes

I have this graph problem where i have a number of Nodes (bus stops ) and some Special nodes (Bus Stations) , I have to cover all the Nodes - Assign bus routes that cover all of them - while starting and ending at a station and I have some restrictions on number of busses I can use , Any ideas how I should start?
The problem of finding the shortest path that connects all nodes (with the bus stations restriction) is reduceable from the Traveling Salesman Problem with the reduction of: given a TSP problem, create an instance of this problem with 1/2 stations/"special nodes" (depending weither or not you can come back to the same station).
Using this reduction - if this problem is solveable polynomially - so is TSP.
Thus - the problem is NP-Hard, and there is no known polynomial solution to it (and the assumption is - one does not exist, though it is not proven yet)
Some alternative are heuristic algorithms such as Genetic Algorithm and Hill Climbing, approximation algorithms, or exponential algorithms (which can be used to find an optimal solutions if the data is relatively small) like Dynamic Programming or branch and bound.
EDIT: (response to edited question)
Even if you can use several buses - but a limited number of them - the problem is still NP-Hard, because (assuming the number of buses is constant/given in unary coding): you can "duplicate" the graph to k distinct components (where k is the limited number of buses) - and you have yourself a new TSP problem for each component.
Here's a simple idea:
Remove the start and end node from the graph.
Search for the minimum spanning tree
Connect the start-end node to the spanning tree.
With that you can have a minimal cover solution.
Of course, if you need to visit each node once, then as stated, this is an NP-Hard problem.

Resources