I came across a definition of Perfect matching: a set of edges that touches each node exactly once.
However, i didnt really understand the definition. Can somebody give me an example of any such edge. Or may be point me towards some reference that does.
I tried to google but it didnt give me any example.
A perfect matching set is any set of edges in a graph where every vertex in the graph is touched by exactly one edge in the matching set. If you consider a graph with 4 vertices connected so that the graph resembles a square, there are two perfect matching sets, which are the pairs of parallel edges. Since all the vertices are touched exactly once by either pair. If you think about a graph with 3 vertices connected like a triangle, there is no perfect matching set, because if you take any pair of edges, one vertex is touched twice, but a single edge will always miss a vertex.
http://en.wikipedia.org/wiki/Perfect_matching
Your question mentions a tree, but a tree is just a special type of graph, so it still works the same.
In fact, any graph with odd number of vertices cannot have a perfect matching edge set.
N edges => 2 * N vertices. Since no vertex once touched should not be touched again.
Related
This problem may be related to this post.
This problem also asked here but with a different taste.
Consider an (undirected) square graph with a periodic boundary condition. Then find a complete cycle graph with length equal to 4. now I want to assign a unique representative to each cycle from its elements. Therefore in a square graph with n_v vertex i will find n_f=n_v 4-cycles and n_v representative for the cycles. For the square graph, everything is simple. just assign the bottom left vertex of each plaque(4-cycles).
(i just show first 4-cycle)
Now, I want to generalize it for other structures. consider (undirected) kagome graph with proper boundary condition,
(here I just show 3 distinct cycles)
In this case for assigning a vertex to cycles cover, you need three different length cycles. which show by similar color with the assigned vertex. However, now I want to generalize this to other complicated graphs. I want to know is this problem has a name and about its possibility or algorithm. For example, we cannot do it in a triangular graph:
This problem solved here.
I)Let show all faces and vertices by \alpha_i, where i contain
vertices and faces.
II) make a graph which relates \alpha_i (from i
in face group) to \alpha_j (to j in vertex group), if j(vortex)
belong to i(face).
III) find the independent edge set of this
graph gives for any vortex a face.
Please see here for additional information.
I'm having trouble understanding the general idea behind the MAX-CUT problem. Consider the graph below.
The MAX-CUT asks us to find the cut that maximizes the number of edges that it touches. I can trivially draw this.
I don't get what the problem is? For any graph, it's trivial for me to find the line that crosses all the edges. Am I misunderstanding the problem?
EDIT:
In response to David, here's a picture of my version of MAX-CUT where we end on an ending vertex
The formal definition of MAX-CUT is to find a set of vertices S to maximize the number of edges with exactly one endpoint in S. Graphically, this means drawing a simple closed curve and counting only the number of edges crossed an odd number of times.
you are misunderstanding the problem. The goal is to separate the vertices in a bipartite set, meaning into two groups. As an example, look at the bottom and top left vertices, which you disconnected with your cut. These two vertices must therefore be in a different sets. At the same time both of these vertices are disconnected from the vertex in the middle left. This would mean that this vertex also has to be in a different group, which is impossible.
Cutting the edges means assigning the vertices to opposite groups. But you can't assign all vertices to opposite groups because there are only two groups you can choose from.
The problem: you need to find the minimum spanning tree of a graph (i.e. a set S of edges in said graph such that the edges in S together with the respective vertices form a tree; additionally, from all such sets, the sum of the cost of all edges in S has to be minimal). But there's a catch. You are given an initial set of fixed edges K such that K must be included in S.
In other words, find some MST of a graph with a starting set of fixed edges included.
My approach: standard Kruskal's algorithm but before anything else join all vertices as pointed by the set of fixed edges. That is, if K = {1,2}, {4,5} I apply Kruskal's algorithm but instead of having each node in its own individual set initially, instead nodes 1 and 2 are in the same set and nodes 4 and 5 are in the same set.
The question: does this work? Is there a proof that this always yields the correct result? If not, could anyone provide a counter-example?
P.S. the problem only inquires finding ONE MST. Not interested in all of them.
Yes, it will work as long as your initial set of edges doesn't form a cycle.
Keep in mind that the resulting tree might not be minimal in weight since the edges you fixed might not be part of any MST in the graph. But you will get the lightest spanning tree which satisfies the constraint that those fixed edges are part of the tree.
How to implement it:
To implement this, you can simply change the edge-weights of the edges you need to fix. Just pick the lowest appearing edge-weight in your graph, say min_w, subtract 1 from it and assign this new weight,i.e. (min_w-1) to the edges you need to fix. Then run Kruskal on this graph.
Why it works:
Clearly Kruskal will pick all the edges you need (since these are the lightest now) before picking any other edge in the graph. When Kruskal finishes the resulting set of edges is an MST in G' (the graph where you changed some weights). Note that since you only changed the values of your fixed set of edges, the algorithm would never have made a different choice on the other edges (the ones which aren't part of your fixed set). If you think of the edges Kruskal considers, as a sorted list of edges, then changing the values of the edges you need to fix moves these edges to the front of the list, but it doesn't change the order of the other edges in the list with respect to each other.
Note: As you may notice, giving the lightest weight to your edges is basically the same thing as you suggest. But I think it is a bit easier to reason about why it works. Go with whatever you prefer.
I wouldn't recommend Prim, since this algorithm expands the spanning tree gradually from the current connected component (in the beginning one usually starts with a single node). The case where you join larger components (because your fixed edges might not all be in a single component), would be needed to handled separately - it might not be hard, but you would have to take care of it. OTOH with Kruskal you don't have to adapt anything, but simply manipulate your graph a bit before running the regular algorithm.
If I understood the question properly, Prim's algorithm would be more suitable for this, as it is possible to initialize the connected components to be exactly the edges which are required to occur in the resulting spanning tree (plus the remaining isolated nodes). The desired edges are not permitted to contain a cycle, otherwise there is no spanning tree including them.
That being said, apparently Kruskal's algorithm can also be used, as it is explicitly stated that is can be used to find an edge that connects two forests in a cost-minimal way.
Roughly speaking, as the forests of a given graph form a Matroid, the greedy approach yields the desired result (namely a weight-minimal tree) regardless of the independent set you start with.
I seem to have found an algorithm but am having trouble understanding it, I was wondering if any of you knew the generic outline of the algorithm.
Here is the link to the algorithm I found on page 2
http://www.cse.iitb.ac.in/~sundar/cs435/lecture23.pdf
Algorithm is simple as that:
Find unmatched vertex, mark it as not included in minimum vertex cover.
Mark all matched neighbours of this vertex as included in minimum vertex cover.
Treat all mates of vertexes from previous step as unmatched vertexes and repeat step 1.
If recursion ended, repeat from step 1 (that is case of several connected components of graph).
If there is no unmatched vertexes, take all remaining pairs and mark them any way you like (remember that one vertex in pair has to
be included in minimum vertex cover, and other one has to be not
included).
first you should know bipartite graph, two sets of vertexes, and edges, ok, you know that now.
then you need to choose some vertexes from the two sets, to cover all the edges. As long as one vertex is chosen, all the edges link to it is covered. Now your task is to choose the minimum number of vertexes, to cover all the edges.
the principle means, the minimum number you need equals to the number of max matching pairs.
Given a directed graph, I need to find the minimum set of vertices from which all other vertices can be reached.
So the result of the function should be the smallest number of vertices, from which all other vertices can be reached by following the directed edges.
The largest result possible would be if there were no edges, so all nodes would be returned.
If there are cycles in the graph, for each cycle, one node is selected. It does not matter which one, but it should be consistent if the algorithm is run again.
I am not sure that there is an existing algorithm for this? If so does it have a name? I have tried doing my research and the closest thing seems to be finding a mother vertex
If it is that algorithm, could the actual algorithm be elaborated as the answer given in that link is kind of vague.
Given I have to implement this in javascript, the preference would be a .js library or javascript example code.
From my understanding, this is just finding the strongly connected components in a graph. Kosaraju's algorithm is one of the neatest approaches to do this. It uses two depth first searches as against some later algorithms that use just one, but I like it the most for its simple concept.
Edit: Just to expand on that, the minimum set of vertices is found as was suggested in the comments to this post :
1. Find the strongly connected components of the graph - reduce each component to a single vertex.
2. The remaining graph is a DAG (or set of DAGs if there were disconnected components), the root(s) of which form the required set of vertices.
[EDIT #2: As Jason Orendorff mentions in a comment, finding the feedback vertex set is overkill and will produce a vertex set larger than necessary in general. kyun's answer is (or will be, when he/she adds in the important info in the comments) the right way to do it.]
[EDIT: I had the two steps round the wrong way... Now we should guarantee minimality.]
Call all of the vertices with in-degree zero Z. No vertex in Z can be reached by any other vertex, so it must be included in the final set.
Using a depth-first (or breadth-first) traversal, trace out all the vertices reachable from each vertex in Z and delete them -- these are the vertices already "covered" by Z.
The graph now consists purely of directed cycles. Find a feedback vertex set F which gives you a smallest-possible set of vertices whose removal would break every cycle in the graph. Unfortunately as that Wikipedia link shows, this problem is NP-hard for directed graphs.
The set of vertices you're looking for is Z+F.