Eliminate cycles in a graph removing vertices - algorithm

does anyone here know if it's possible to eliminate all cycles in a undirected and unweighted graph (n vertices) removing vertices in a way the number of removed vertices is minimized, in O(n^2) ?
In the worst case, the graph can be a complete one.
If it's possible, how can i do it?
If it's not, why?
Thank you

Take any undirected, unweigthed graph, and double up all the edges so that there's a cycle between each pair of adjacent vertices.
Now the minimum set of vertices that eliminates all cycles is also the minimum vertex cover of both the original and modified graphs. See https://en.wikipedia.org/wiki/Vertex_cover
Finding a minimum vertex cover is an NP-hard problem, so your problem is also NP-hard.
If you don't want to allow double edges, then you can add dummy vertices to hold the new edges and your problem still solves vertex cover.

This problem is called Feedback Vertex Set, and unfortunately it's NP-hard, meaning no one knows a polynomial-time algorithm for solving it.

Related

Choose edges from weighted graph, such that each vertex is an endpoint of one edge, and the sum of edge weights is minimized

For simplication, we can assume that the graph G=(V,E) has 2N vertexes and the answer has N edges.
I have learned that if the graph is bipartite, Hungarian algorithm works well. However, I wonder if there is any nontrivial solution(i.e. a polynomial one) for a general graph.
Any polynomial solutions, as well as a proof of NP Complexity, are welcome.
If you want every vertex be incident to exactly one edge, then you need to find perfect matching. But perfect matching not always exists even for a graph with even number of vertices.
You can see example in this answer.

Non-directed graph algorithm to find lowest cost path

I know a few algorithms that are able to find the lowest cost path for directed graph (just as Dijkstra and Floyd).
Is there any algorithm that works for non-directed graphs?
My problem is: I need to find the lowest cost path from a to b passing through all vertexes (undirected graph).
My problem is: I need to find the lowest cost path from a to b passing
through all vertexes (non-oriented graph)
This is the Traveling Salesman Problem, which is NP-Hard, so there is no known efficient solution to it.
However, if the graph is fairly small, there are some techniques to solve it optimally (in exponential time), like Dynamic Programming.
In general, changing an undirected graph to a directed one is fairly easy and is done by changing an undirected edge {u,v} to two directed edges (u,v) and (v,u)
Provided you have nonnegative edge values, you could consider every edge in an undirected graph as two edges in a directed graph, one pointed to and from connected vertices. Then you could use one of many algorithms including the ones you listed.

Partially coloring a graph with 1 color

I just started reading graph theory and was reading about graph coloring. This problem popped in my mind:
We have to color our undirected graph(not completely) with only 1 color so that number of colored nodes are maximized. We need to find this maximum number. I was able to formulate an approach for non cyclic graphs :
My approach : First we divide graph into isolated components and do this for each component. We make a dfs tree and make 2 dp arrays while traversing it so that root comes last :
dp[0][u]=sum(dp[1][visited children])
dp[1][u]=sum(dp[0][visited children])
ans=max(dp[1][root],dp[0][root])
dp[0][i] , dp[1][i] are initialized to 0,1 respectively.
Here 0 signifies uncolored and 1 signifies colored.
But this does not work for cyclic graphs as I have assumed that no visited children are connected.
Can someone guide me in the right direction on how to solve this problem for cyclic graphs(not by brute force)? Is it possible to modify my approach or do we need to come up with a different approach? Would a greedy approach like coloring a nodes with least edges work?
This problem is NP-Hard as well, and is known as maximum independent set problem.
A set S<=V is said to be Independent Set in a graph if for each two vertices u,v in S, there is no edge (u,v).
The maximum size of S (which is the number you are seeking) is called the independence number of the graph, and unfortunately finding it is NP-Hard.
So, unless P=NP, your algorithm fails for general purposes graphs.
Proving it is fairly simple, given a graph G=(V,E), create the complementary graph G'=(V,E') where (u,v) is in E' if and only if (u,v) is NOT in E.
Now, given a graph G, there is a clique of size k if and only if there is an independent set of size k in G', using the same vertices (since if (u,v) are two vertices the independent set, there is no edge (u,v) in E', and by definition there is an edge in E. Repeat for all vertices in the independent set, and you got a clique in G).
Since clique problem is NP-Hard, this makes this one such as well.

NP-Complete? Optimal graph embedding for a graph with specific constraints

I have a grid based graph, where nodes and edges occupy cells. Edges can cross, but cannot travel on top of each other in the same direction.
Lets say I want to optimize the graph so that the distance covered by edges is minimized.
I am currently using A* search for each connection, but the algorithm is greedy and does not plan ahead. Consider the diagram below, where the order in which connections are made is changed (note also that there can be multiple shortest paths for any given edge, see green and
purple connections).
My intuition says this is NP-Complete and that an exhaustive search is necessary, which will be extremely expensive as the size of the graph grows. However, I have no way of showing this, and it is not quite the same as other graph embedding problems which usually concern minimization of crossing.
You didn't really describe your problem and your image is gone, but your problem sounds like the minimum T-join problem.
The minimum T-join problem is defined on a graph G. You're given a set T of even size, and you're trying to find a subgraph of the graph where the vertices of T have odd degree and the other vertices have even degree. You've got weights on the edges and you're trying to minimise the sum of the weights of edges in the subgraph.
Surprisingly, the minimum T-join problem can be solved in polynomial time thanks to a very close connection with the nonbipartite matching problem. Namely, if you find all-pairs shortest paths between vertices of T, the minimum T-join is attained by the minimum-weight perfect matching of vertices in T, where there's an edge between two vertices whose length is the length of the shortest path in G.
The minimum T-join will be a collection of paths. If two distinct paths, say a->b and c->d, use the same edge uv, then they can be replaced by a->u->c and b->v->d and reduce the cost of the T-join. So it won't use the same edge twice.

Is the problem of finding the simple path with maximum cost in a weighted undirected graph with the same number of vertex and edges NP-Complete?

Hello and thanks again for reading this.
I need to know now if the problem of finding the simple path with maximum cost in a weighted undirected graph with the same number of vertex and edges is NP-Complete or not?
Input: Graph G = (V,E) with V (vertex) = E (edges)
Output: The cost of the most expensive path in the graph G.
Could you provide any reference to an article where I can review this.
Thank you very much for your time.
Sincerely,
Alex.
If the graph is not necessarily connected, then any instance of the longest path problem can be reduced to this problem by adding extra isolated vertices to the input graph to make the number of nodes and edges the same. If this isn't thyroid case, and the graph must be connected, then the input graph must have exactly one cycle, since a graph with n-1 edges is a tree. IF you find this cycle with a DFS and contract it to a single node, you then have a tree. It's easy to do longest path computations here; just consider all pairs of edges and get the cost of the unique path between them. If you take this path ans then expand it in the original graph by walking around the cycle where you originally went through the contracted node, I think you get the longest path in polynomial time.
This problem is called the Longest Path Problem, and is NP-complete.
The restriction |V| = |E| doesn't help at all. You can solve an arbitrary graph by adding unconnected vertices until you satisfy the relation.

Resources