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.
Related
My programming homework requires me to determine from a given set of dominoes if we can chain them in a way that all dominoes have equal number of dots on the touching sides. The two ends don't have to have matching sides.
Same task as this, except the matching ends part: https://exercism.org/tracks/elixir/exercises/dominoes
I tried to find a solution using graphs, but no luck (couldn't find a solution to determine Hamiltonian connectedness). My other idea would be to use Backtrack Search, but that doesn't seem very elegant.
You can solve the problem using graph theory, construct a graph were you have as many nodes as the maximum possible number of dots on some side of a domino. Then for each domino add an undirected edge between the nodes representing the number of dots on both of its sides (so a domino of [3,5] dots will add an edge between nodes 3 and 5). Your problem now is to find a Eulerian path in this graph.
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.
Below is the exercise 5.25 in 《Introduction to algorithms, a creative approach》. After reading it several times, I still can't understand what it means. I can color a tree with 2 colors very easily and directly using the method it described, not 1+LogN colors.
《Begin》
This exercise is related to the wrong algorithm for determining whether a graph is bipartite, described in Section 5.11.In some sense, this exercise shows that not only is the algorithm wrong, but also the simple approach can not work. Consider the more general problem of graph coloring: Given an undirected graph G=(V,E), a valid coloring of G is an assignment of colors to the vertices such that no two adjacent vertices have the same color. The problem is to find a valid coloring, using as few colors as possible. (In general, this is a very difficult problem; it is discussed in Chapter 11.)
Thus, a graph is bipartite if it can be colored with two colors.
A. Prove by induction that trees are always bipartite.
B. We assume that the graph is a tree(which means that the graph is bipartite). We want to find a partition of the vertices into the two subsets such that there are no edges connecting vertices within one subset.
Consider again the wrong algorithm for determining whether a graph is bipartite, given in Section 5.11: We take an arbitrary vertex, remove it, color the rest(by induction), and then color the vertex in the best possible way. That is, we color the vertex with the oldest possible color, and add a new color only if the vertex is connected to vertices of all the old colors. Prove that, if we color one vertex at a time regardless of the global connections, we may need up to 1+logN colors.
You should design a construction that maximizes the number of colors for every order of choosing vertices. The construction can depend on the order in the following way.
The algorithm picks a vertex as a next vertex and starts checking the vertex’s edges. At that point, you are allowed to add edges incident to this vertex as you desire, provided that the graph remains a tree, such that, at the end, the maximal number of colors will be required. You can not remove an edge after it is put in(that would be cleanining the algorithm, which has already seen the edge). The best way to achieve this construction is by induction. Assume that you know a construction that requires<=k colors with few vertices, and build one that requires k+1 colors without adding too many new vertices.
《End》
Here's an interesting problem/riddle a friend asked me recently:
You are painting the lines of a tennis court. You have a machine to paint straight lines, but once it is turned on, you can't stop it until the job is done. Clearly you will need to go over some lines twice. What is the smallest amount of extra paint you have to use, in feet?
The dimensions of a court:
The sum of all lines is 480ft. I happen to know that the answer is 63ft extra (543ft total), but I can't help but wonder what the best algorithm is to solve this.
It seems similar to the traveling salesman problem, where each line on the court is represented by a vertex in a graph and junctions of court-lines translate to edges. (Otherwise, if lines were edges and corners were vertices, it would require a path that goes through all edges, and I don't know of any algorithms for that). Maybe you need to be more clever about how junctions of lines are represented and I have some ideas about that, but nothing has really worked yet.
I think the problem is small enough, though, that it can be brute-force-checked with all paths through the line graph. How would you code that?
An undirected graph has an Eulerian trail if and only if at most two vertices have odd degree, and if all of its vertices with nonzero degree belong to a single connected component. ( Found from http://en.wikipedia.org/wiki/Eulerian_path )
When we get a non-Eulerian graph, we can change it to an Eulerian by adding edges to the odd degree vertices.
So, this problem is turned to: find the lowest cost to turn the graph to a Eulerian.
The algorithm should be:
list all vertices with odd degree , suggest it is a list_vodd[];
find the shortest edge between the vertices in list_vodd[], get two vertices of the edge: pa, pb;
add an edge between pa,pb ( which means this edge should be paint twice );
delete pa,pb from list_vodd[];
goto 2 until there are only two vertices in list_vodd[].
use any existing algorithm to find out a Eulerian router in the new graph with the added edges.
I'm a little late to the game here, but I came across this when I was trying to find an algorithm to determine the shortest path to hike every trail in a state park. Here's a sketch that explains why the answer is 63
As Richard mentioned, this is a Chinese Postman problem. Since the problem didn't specify that we have to start and end in the same location we can use a semi-eulerian graph, which is why all the nodes have an even number, except the start and end points which share a common edge.
Here is a very nice video that explains how to graph and solve this type of problem.
https://www.youtube.com/watch?v=spaUY8PlyYA
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.