1 / 10

Algorithms Homework Assignment #9

Algorithms Homework Assignment #9. Jing- Jie Lin. HW#9 No.2. (a) Give an example of a weighted connected undirected graph G = (V, E) and a vertex v, such that the minimum-cost spanning tree of G is the same as the shortest-path tree rooted at v. (10pt)

Télécharger la présentation

Algorithms Homework Assignment #9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AlgorithmsHomework Assignment #9 Jing-Jie Lin

  2. HW#9 No.2 (a) Give an example of a weighted connected undirected graph G = (V, E) and a vertex v, such that the minimum-cost spanning tree of G is the same as the shortest-path tree rooted at v. (10pt) (b) Give an example (5pt) of a weighted connected undirected graph G = (V, E) and a vertex v, such that the minimum-cost spanning tree of G is very different from the shortest path tree rooted at v. Can the two trees be completely disjoint?(5pt)

  3. HW#9 No.2 (b) No, it is impossible that the two trees are completely disjointed. Let Tm denote the minimum cost spanning tree of G Ts be the shortest path tree rooted at v. • v has only one edge The only edge must be both in Tm and in Ts. Otherwise v will be disconnected from Tm and from T • v has more than oneedge Let (v, u) be the minimum weighted edge among all edges of v. Then (v, u) must belong to both Tm and Ts. • If (v, u) is not in Tm, Tm must include some other edge (v, w). But by replacing (v, w) with (v, u) in Tm=> a new tree with lower weight • If (v, u) is not in Ts, the shortest path π from v to u must include some other edge (v, w), but the edge (v, u) is shorter than π

  4. HW#9 No.3 (a) Run the strongly connected components algorithm on the directed graph shown in Figure 1. (10pt) • When traversing the graph, the algorithm should follow the given DFS numbers. • Show the High values as computed by the algorithm in each step. 1 (b) Add the edge (4, 2) to the graph and discuss the changes this makes to the execution of the algorithm. (10pt) 4 9 7 2 6 8 5 3

  5. (a) 1 4 9 7 2 6 8 8 5 3

  6. (a) 8 1 8 7 7 6 6 5 5 4 4 3 3 2 2 1 4 9 max 7 2 6 8 5 max 3 max max max max 9 1 max 3 9 max 9 8 max

  7. (b) 1 4 9 7 2 6 8 5 3

  8. HW#9 No.4 • Let G = (V, E) be a connected weighted undirected graph and T be a minimum-cost spanning tree (MCST) of G. • Suppose that the cost of one edge {u, v} in G is changed (increased or decreased) • {u, v} may or may not belong to T. • Design an algorithm (10pt) to either find a new MCST or to determine that T is still an MCST. • The more efficient your algorithm is, the more points you will be credited for this problem. • Explain why your algorithm is correct(5pt) and analyze its time complexity (5pt).

  9. {u, v} HW#9 No.4 T1 T2 f Lemma: Adding additional edge k to a minimal cost spanning tree T, it will create a cycle . In the cycle, k is the maximum cost edge.

  10. Input: G(V, E): undirected graph, T: MCST, e={u, v} 2 G • Output: T’: new MCST or print “No Change” • 17else if e T and e is decrease then 18 T’ := T + e; • 19 C := Find_Cycle(T, e); • 20for all edge k in C do • 21ifk.weight> w then • 22w := k.weight; 23new_edge:=k; 24 T’ := T’ – new_edge; 25if new_edge = e then 26 print “No Change” 27 else 28return T’; 29 else • 30 print “No Change” AlgorithmnewMCST (G, T, e); 1 begin 2w := e.weight; 3new_edge := e; • 4ife2 T and e is increase then 5T’ := T - e; 6 T1 := DFS_Tree(T’, u); 7 T2 := DFS_Tree(T’, v); 8 for all edges k connecting T1 and T2 do 9ifk.weight < w then 10 w := k.weight; 11new_edge := k; 12 if k =e then 13print “No Change” • 14 else • 15 T’ := T’ + new_edge; • 16 return T’; O(|V|+|E|) O(|V|) O(|V1|+|E1|) O(|V2|+|E2|) O(|E|) Time Complexity: O(|V|+|E|)

More Related