Assume G = (V,E) is a complete graph.
Let the vertices be a set of points in the plane and let the edges be line segments between the points. Let the weight of each edge [a, b] be the length of the segment 'ab'.
After reading about Prim's Algorithm and Kruskal's Algorithm, I have some sound knowledge that these greedy algorithms output the minimum spanning tree of a graph.
My Question is: After obtaining a minimum spanning tree of G, Is there a way to prove that the minimum spanning tree of G is a plane graph?
You can check if the minimum spanning tree is planar as any graph. There are a simple way to check if a graph is planar. The very known Euler formula
“If G is a connected planar graph with e edges and v vertices, where v >= 3, then e <= 3v - 6. Also G cannot have a vertex of degree exceeding 5.”
or you can rely on the following method:
Theorem – “Let G be a connected simple planar graph with e edges and v vertices. Then the number of faces f in the graph is equal to f = e-v+2.”
Euler also showed that for any connected planar graph, the following relationship holds:
v - e + f = 2.
Good lucky
Related
I am trying to design an algorithm where, given a connected weighted graph G = (V, E) and a subset of vertices U that is in V, will construct a minimum spanning tree such that all vertices in U are leaves (other vertices may also be leaves), or returns that no such tree exists (False).
This is all I got, adapting Prim's algorithm (fair warning, its really bad; don't even know if it works/is efficient or what data structures to use, I will accept literally any other correct algorithm instead):
Let x be an arbitrary node in G
Set S = {x}
While S != V:
Let (u,v) be the cheapest edge with u in S and v not in S
Add (u,v) to tree T if u is not in U, add v to S
If all u in U is in the tree T:
return T
Else:
return False
I also have a picture of what I think it would do to this graph I drew:
pic here
A proof that the algorithm is correct would also give me some peace of mind.
If all vertices u ∈ U are to be leaves in a solution, no u can be used in that solution to connect two other vertices. All vertices not in U must be connected by edges not incident to any u.
Remove U and all edges incident to U. Find the minimum spanning tree, then connect each u to the tree by the smallest-weighted edge available from those we removed.
Hello this is my first question. I met a homework in algorithm and probability that I can't find a clue to calculate.
Question:
Computing Number of Triangles in a Graph: Given an undirected graph G = (V, E), a triangle in G is a clique of size 3 (formally, a set of nodes {u, v, w} is a triangle in G if (u, v), (v, w), (u, w) are all edges of G). Consider the following algorithm for approximating the number of triangles in a graph. First construct a sampled graph G' = (V, E') as follows. The vertex set of G' is same as that of G. For every e ∈ E, put e in E' with probability p (think of p as, say, 0.1). In this new sampled graph G', count the number of triangles and let T' be the number of triangles in G' (assume that you have given a black box subroutine to count the number of triangles in G' ). Then output T̃= T'/p.
Show that the expected value of T̃=T ,T is the triangle number of original graph G.
I am confusing that the edge in G or G' to form a triangle is not independent since two adjacent triangles in G might share the edge. And not the all the pair of vertices in G can form a edge in G', only those edges are in G will be present in G' with p. It's hard for me to think of the relationship of number of edges and number of triangles in G or G'.
Hope someone can give me some hints, even not the whole solution is OK.
the edge in G or G' to form a triangle is not independent since two adjacent triangles in G might share the edge
Doesn't matter. The sum of expectations is the expectation of the sum regardless of correlation, so you can reason about the triangles individually. (Higher moments, were you concerned about analyzing the estimation quality of this algorithm, would be trickier.)
I have a connected graph G=(V,E) V={1,2,...,n} and a cost function c:E->R
and a second partial graph G'=(V,T) where T={ for every vertex v∈ V find the neighbor with the minimum cost and add the new edge to T}
If G' graph has at least 2 connected components with the set of vertices we consider the graph H where
iff the set of edges (from the initial graph G) is not null.We define over the edges of H a cost function.
Let's say I choose V(H)={a,e,f} and E(H)={ae,af,fe} and
E12={ab,bc,bd,ed}
E23={eg,ef} E31={fc,fd}
c'(ae)=min{c(ab),c(bc),c(bd),c(ed)}=4
c'(af)=min{c(fc),c(fd)}=9
c'(fe)=min{c(eg),c(ef)}=8
Now for every edge e ∈ E(H) we note with e' the edge (from the original graph G)
for which this minimum is attained.
So e'={bc,df,eg} because bc=4 , df=9 and eg=8 and are the min edges that connect my components.
And I have a minimum spanning tree in H relative to the cost function c' and A' is the set of edges for this tree.
So A'={ae,fe} (I deleted the edge with the maximum cost=af from my graph H to create a min spanning tree)
and I have another set of edges A'={e'|e∈A'} and
is a min spanning tree in G relative to the function cost c.
But none of my edges from A' are the same with the ones from e'.
What I'm I doing wrong?
Looks like you're implementing Boruvka's algorithm. If you look at the notation, it says there's an edge from one new node vC1 to a new node vC2 if there are a pair of nodes x ∈ C1 and y ∈ C2 that are adjacentnin the original graph G. In other words, there's an edge between two new nodes if the connected components they correspond to in G' are adjacent in G. The cost of the edge running between them is then the lowest of the costs of any of the edges running between those CC's in the original graph G.
I am required to use a greedy algorithm to resolve this problem (here m is the number of edges and n is the number of vertices in the original graph). Intuitively, I know it is somehow about density of graph (due to m/n*(n-1) part), so I try to use greedy algorithm to remove the vertex with minimum degree each iteration until I get a k nodes graph, but I don't know how can I GARUNTEE the algorithm give me the final graph with at least m*k*(k-1)/n*(n-1) edges.
Looking for any hints, Thanks.
Let's define the density of a graph p=m/(n*(n-1)) (for undirected graph it should be p=2*m/(n*(n-1)). Note that for a graph with density p and k vertices, it has (k*(k-1)) * p edges. Also note that when you greedily remove a vertex with the minimum degree, it won't decrease the density of the graph (will proof it below). So when you get the subgraph with k vertices, its density is equal to or greater than m/(n*(n-1)), then the subgraph contains at least k*(k-1)(m*/n*(n-1)) edges.
Let G be a graph with m edges and n vertices, then p=m/n. Let d the minimum degree of all vertices. then we have n * d <= m i.e., d <= m/n. So when you remove the vertex with the minimum degree, you get a graph with m-d edges and n-1 vertices, then the density of the new graph will be p'=(m-d)/(n-1) >= (m-m/n)/(n-1) = m/n = p. So we have that the greedy algorithm won't decrease the density of a graph.
Dijkstra's is typically used to find the shortest distance between two nodes in a graph. Can it be used to find a minimum spanning tree? If so, how?
Edit: This isn't homework, but I am trying to understand a question on an old practice exam.
The answer is no. To see why, let's first articulate the question like so:
Q: For a connected, undirected, weighted graph G = (V, E, w) with only nonnegative edge weights, does the predecessor subgraph produced by Dijkstra's Algorithm form a minimum spanning tree of G?
(Note that undirected graphs are a special class of directed graphs, so it is perfectly ok to use Dijkstra's Algorithm on undirected graphs. Furthermore, MST's are defined only for connected, undirected graphs, and are trivial if the graph is not weighted, so we must restrict our inquiry to these graphs.)
A: Dijkstra's Algorithm at every step greedily selects the next edge that is closest to some source vertex s. It does this until s is connected to every other vertex in the graph. Clearly, the predecessor subgraph that is produced is a spanning tree of G, but is the sum of edge weights minimized?
Prim's Algorithm, which is known to produce a minimum spanning tree, is highly similar to Dijkstra's Algorithm, but at each stage it greedily selects the next edge that is closest to any vertex currently in the working MST at that stage. Let's use this observation to produce a counterexample.
Counterexample: Consider the undirected graph G = (V, E, w) where
V = { a, b, c, d }
E = { (a,b), (a,c), (a,d), (b,d), (c,d) }
w = {
( (a,b) , 5 )
( (a,c) , 5 )
( (a,d) , 5 )
( (b,d) , 1 )
( (c,d) , 1 )
}
Take a as the source vertex.
Dijkstra's Algorithm takes edges { (a,b), (a,c), (a,d) }.
Thus, the total weight of this spanning tree is 5 + 5 + 5 = 15.
Prim's Algorithm takes edges { (a,d), (b,d), (c,d) }.
Thus, the total weight of this spanning tree is 5 + 1 + 1 = 7.
Strictly, the answer is no. Dijkstra's algorithm finds the shortest path between 2 vertices on a graph. However, a very small change to the algorithm produces another algorithm which does efficiently produce an MST.
The Algorithm Design Manual is the best book I've found to answer questions like this one.
Prim's algorithm uses the same underlying principle as Dijkstra's algorithm.
I'd keep to a greedy algorithm such as Prim's or Kruskal's. I fear Djikstra's won't do, simply because it minimizes the cost between pairs of nodes, not for the whole tree.
Of course, It's possible to use Dijkstra for minimum spanning tree:
dijsktra(s):
dist[s] = 0;
while (some vertices are unmarked) {
v = unmarked vertex with
smallest dist;
Mark v; // v leaves “table”
for (each w adj to v) {
dist[w] = min[ dist[w], dist[v] + c(v,w) ];
}
}
Here is an example of using Dijkstra for spanning tree:
You can find further explanation in Foundations of Algorithms book, chapter 4, section 2.
Hope this help