B AB 5 C AC 3 D ABGED 9 E ABGE 7 F ABGEF 8 G ABG 6 A BEDA 3 C BC 1 D BCD 2 E BE 1 F BEF 2 G BG 1


 Joy Sharp
 1 years ago
 Views:
Transcription
1 p a. Find the shortest path from A to all other vertices for the graph in Figure 9.8. b. Find the shortest unweighted path from B to all other vertices for the graph in Figure 9.8. A 5 B C D G F E a. source destination path cost A B AB 5 C AC D ABGED 9 E ABGE 7 F ABGEF 8 G ABG 6 b. Source Destination path cost B A BEDA C BC D BCD E BE F BEF G BG p. 9. (ZOJ 56) a. Explain how to modify Dijkstra's algorithm to produce a count of the number of different minimum paths from v to w. b. Explain how to modify Dijkstra's algorithm so that if there is more than one minimum path from v to w, a path with the fewest number of edges is chosen.
2 Answer a: void Dijkstra( Table T ) /* T[ ].Count is initialized to be. T[start].Count = */ vertex v, w; for ( ; ; ) v = smallest unknown distance vertex; if ( v == NotAVertex ) break; T[v].Known = True; for ( each w adjacent to v ) if(!t[w].known ) if( T[v].Dist + Cvw < T[w].Dist ) Decrease( T[w].Dist to T[v]+Cvw ) T[w].Path = v; T[w].Count = T[v].Count; /* NOT T[w].Count = */ else if( T[v].Dist + Cvw == T[w].Dist ) T[w].Count += T[v].Count; /* NOT T[w].Count += */ Answer b: void Dijkstra( Table T ) /* T[ ].Count is initialized to be */ vertex v, w; for ( ; ; ) v = smallest unknown distance vertex; if ( v == NotAVertex ) break; T[v].Known = True; for ( each w adjacent to v ) if(!t[w].known ) if( T[v].Dist + Cvw < T[w].Dist ) Decrease( T[w].Dist to T[v]+Cvw ) T[w].Path = v; T[w].Count = T[v].Count + ; else if( ( T[v].Dist + Cvw == T[w].Dist ) && ( T[v].Count + < T[w].Count ) ) T[w].Count = T[v].Count + ; T[w].Path = v; /* DO NOT forget this */
3 p. 9. Find the maximum flow in the network of Figure Answer: A B C s D E F 6 G H I t p. 9.5 a. Find a minimum spanning tree for the graph in Figure 9.8 using both Prim's and Kruskal's algorithms. b. Is this minimum spanning tree unique? Why? Answer a: They are the same A B C D E F G H I 7 J Answer b: This minimum spanning tree is not unique. For example, another minimum spanning tree obtained from Prim s algorithm is: A B C D E F G H I 7 J
4 p Write a program to find the strongly connected components in a digraph. #define MaxVertices /* maximum number of vertices */ typedef int Vertex; /* vertices are numbered from to MaxVertices */ typedef enum FALSE, TRUE boolean; /* declarations for a graph with adjacency list representation */ #ifndef _Graph_h struct VNode; typedef struct VNode *PtrToVNode; struct GNode; typedef struct GNode *PtrToGNode; typedef PtrToGNode Graph; /* create a graph with NumOfVertices vertices and no edge */ Graph CreateGraph( int NumOfVertices ); /* insert edge V>W to G */ boolean InsertEdge( Vertex V, Vertex W, Graph G ); /* reverse all the edges in G and return the resulting graph Gr */ Graph ReverseGraph( Graph G ); /* free spaces taken by G */ void DeleteGraph( Graph G ); /* implementations of the above functions are omitted */ #endif /*_Graph_h */ struct VNode Vertex Vert; PtrToVNode Next; ; struct GNode int NumOfVertices; int NumOfEdges; PtrToVNode *Array; ; boolean Visited[MaxVertices]; /* global mark for visited vertices */ Vertex DfsOrder[MaxVertices]; /* store vertices in dfs order */ int DfsNum; /* dfs number for vertices */
5 void PostOrder( Vertex V ) /* store vertices during postorder dfs */ DfsOrder[DfsNum++] = V; void PrintV( Vertex V ) /* print V during postorder dfs */ printf("%d ", V); void PostorderDfs( Vertex V, Graph G, void (*f)(vertex V) ) /* postorder dfs template with visiting function f */ PtrToVNode W; Visited[V] = TRUE; for ( W=G>Array[V]>Next; W; W=W>Next ) if (!Visited[W>Vert] ) PostorderDfs( W>Vert, G, (*f) ); (*f)(v); void StronglyConnectedComponents( Graph G ) /* print the strongly connected components in G */ /* output format: V, V,... V, V, */ Graph Gr; Vertex V; /* Step : mark the postorder dfs number for each vertex in G */ InitializeVisited( G>NumOfVertices ); /* Visited[ ] is initialized to be FALSE */ DfsNum = ; for ( V=; V<G>NumOfVertices; V++ ) if (!Visited[V] ) PostorderDfs( V, G, PostOrder ); /* end for */ /* Step : reverse edges in G and save the resulting graph in Gr */ Gr = ReverseGraph( G ); if (!Gr )
6 printf("program failed: cannot reverse graph.\n"); else /* Step : print components by postorder dfs on Gr */ InitializeVisited( Gr>NumOfVertices ); while ( DfsNum ) /* always start at the vertex with the largest dfs number */ V = DfsOrder[DfsNum]; if (!Visited[V] ) /* print this component in a line*/ printf( " " ); PostorderDfs( V, Gr, PrintV ); printf( "\n" ); /* end  if */ /* end  while */ DeleteGraph( Gr ); /* free space */ /* end  else */ Sketch of the proof of correctness:. V, W Comp(G) Path(V>W) and Path(W>V) in both G and Gr;. V, W Comp(G) V, W DfsT(G) and DfsT(Gr);. For V DfsT(Gr) with X as the root, Path(X>V) in Gr, and hence Path(V>X) in G.. Step V, X DfsT(G); 5. DfsNum(X) > DfsNum(V) V must be numbered before X in DfsT(G); 6. Step 5 V is a descendant of X in DfsT(G) since it was a postorder visit; 7. Step 6 Path(X>V) in G. G/G r DfsT(G) DfsT(G r )
(0, 0) : order 1; (0, 1) : order 4; (0, 2) : order 2; (0, 3) : order 4; (1, 0) : order 2; (1, 1) : order 4; (1, 2) : order 2; (1, 3) : order 4.
11.01 List the elements of Z 2 Z 4. Find the order of each of the elements is this group cyclic? Solution: The elements of Z 2 Z 4 are: (0, 0) : order 1; (0, 1) : order 4; (0, 2) : order 2; (0, 3) : order
More informationScientific collaboration networks. II. Shortest paths, weighted networks, and centrality
PHYSICAL REVIEW E, VOLUME 64, 016132 Scientific collaboration networks. II. Shortest paths, weighted networks, and centrality M. E. J. Newman Santa Fe Institute, 1399 Hyde Park Road, Santa Fe, New Mexico
More informationThe Set Data Model CHAPTER 7. 7.1 What This Chapter Is About
CHAPTER 7 The Set Data Model The set is the most fundamental data model of mathematics. Every concept in mathematics, from trees to real numbers, is expressible as a special kind of set. In this book,
More informationFast PointtoPoint Shortest Path Computations with ArcFlags
Fast PointtoPoint Shortest Path Computations with ArcFlags Ekkehard Köhler, Rolf H. Möhring, and Heiko Schilling Institute of Mathematics, TU Berlin, Germany {Ekkehard.Koehler Rolf.Moehring Heiko.Schilling}@TUBerlin.DE
More informationAn O(ND) Difference Algorithm and Its Variations
An O(ND) Difference Algorithm and Its Variations EUGENE W. MYERS Department of Computer Science, University of Arizona, Tucson, AZ 85721, U.S.A. ABSTRACT The problems of finding a longest common subsequence
More informationThe Handshake Problem
The Handshake Problem Tamisha is in a Geometry class with 5 students. On the first day of class her teacher asks everyone to shake hands and introduce themselves to each other. Tamisha wants to know how
More informationSizeConstrained Weighted Set Cover
SizeConstrained Weighted Set Cover Lukasz Golab 1, Flip Korn 2, Feng Li 3, arna Saha 4 and Divesh Srivastava 5 1 University of Waterloo, Canada, lgolab@uwaterloo.ca 2 Google Research, flip@google.com
More informationOPRE 6201 : 2. Simplex Method
OPRE 6201 : 2. Simplex Method 1 The Graphical Method: An Example Consider the following linear program: Max 4x 1 +3x 2 Subject to: 2x 1 +3x 2 6 (1) 3x 1 +2x 2 3 (2) 2x 2 5 (3) 2x 1 +x 2 4 (4) x 1, x 2
More informationOn line construction of suffix trees 1
(To appear in ALGORITHMICA) On line construction of suffix trees 1 Esko Ukkonen Department of Computer Science, University of Helsinki, P. O. Box 26 (Teollisuuskatu 23), FIN 00014 University of Helsinki,
More informationCritical points of once continuously differentiable functions are important because they are the only points that can be local maxima or minima.
Lecture 0: Convexity and Optimization We say that if f is a once continuously differentiable function on an interval I, and x is a point in the interior of I that x is a critical point of f if f (x) =
More information4.1 Learning algorithms for neural networks
4 Perceptron Learning 4.1 Learning algorithms for neural networks In the two preceding chapters we discussed two closely related models, McCulloch Pitts units and perceptrons, but the question of how to
More informationInteger Set Library: Manual
Integer Set Library: Manual Version: isl0.15 Sven Verdoolaege June 11, 2015 Contents 1 User Manual 3 1.1 Introduction............................... 3 1.1.1 Backward Incompatible Changes...............
More informationSimplifying Logic Circuits with Karnaugh Maps
Simplifying Logic Circuits with Karnaugh Maps The circuit at the top right is the logic equivalent of the Boolean expression: f = abc + abc + abc Now, as we have seen, this expression can be simplified
More informationKnow the difference between call rerouting and call forwarding. Understand how several sets can share alternative answer points.
Call Rerouting 21 Objectives When you finish this module, you will: Know the difference between call rerouting and call forwarding. Program call handling for Call Rerouting Always. Program call handling
More information51 NUMBER THEORY: DIVISIBILITY; PRIME & COMPOSITE NUMBERS 210 f8
51 NUMBER THEORY: DIVISIBILITY; PRIME & COMPOSITE NUMBERS 210 f8 Note: Integers are the w hole numbers and their negatives (additive inverses). While our text discusses only whole numbers, all these ideas
More informationWHICH SCORING RULE MAXIMIZES CONDORCET EFFICIENCY? 1. Introduction
WHICH SCORING RULE MAXIMIZES CONDORCET EFFICIENCY? DAVIDE P. CERVONE, WILLIAM V. GEHRLEIN, AND WILLIAM S. ZWICKER Abstract. Consider an election in which each of the n voters casts a vote consisting of
More information28 ClosestPoint Problems 
28 ClosestPoint Problems  Geometric problems involving points on the plane usually involve implicit or explicit treatment of distances
More informationMEP Y9 Practice Book A
1 Base Arithmetic 1.1 Binary Numbers We normally work with numbers in base 10. In this section we consider numbers in base 2, often called binary numbers. In base 10 we use the digits 0, 1, 2, 3, 4, 5,
More informationCMSC 451 Design and Analysis of Computer Algorithms 1
CMSC 4 Design and Analysis of Computer Algorithms David M. Mount Department of Computer Science University of Maryland Fall 003 Copyright, David M. Mount, 004, Dept. of Computer Science, University of
More informationA Googlelike Model of Road Network Dynamics and its Application to Regulation and Control
A Googlelike Model of Road Network Dynamics and its Application to Regulation and Control Emanuele Crisostomi, Steve Kirkland, Robert Shorten August, 2010 Abstract Inspired by the ability of Markov chains
More informationDifferent Approaches to White Box Testing Technique for Finding Errors
Different Approaches to White Box Testing Technique for Finding Errors Mohd. Ehmer Khan Department of Information Technology Al Musanna College of Technology, Sultanate of Oman ehmerkhan@gmail.com Abstract
More informationTreerepresentation of set families and applications to combinatorial decompositions
Treerepresentation of set families and applications to combinatorial decompositions BinhMinh BuiXuan a, Michel Habib b Michaël Rao c a Department of Informatics, University of Bergen, Norway. buixuan@ii.uib.no
More informationStatistics Revision Sheet Question 6 of Paper 2
Statistics Revision Sheet Question 6 of Paper The Statistics question is concerned mainly with the following terms. The Mean and the Median and are two ways of measuring the average. sumof values no. of
More informationThe LCA Problem Revisited
The LA Problem Revisited Michael A. Bender Martín Faracholton SUNY Stony Brook Rutgers University May 16, 2000 Abstract We present a very simple algorithm for the Least ommon Ancestor problem. We thus
More informationEnumerating Answers to FirstOrder Queries over Databases of Low Degree
Enumerating Answers to FirstOrder Queries over Databases of Low Degree Arnaud Durand CNRS and ENS Cachan www.logique.jussieu.fr/ durand/ Nicole Schweikardt GoetheUniversität Frankfurt www.tks.cs.unifrankfurt.de/schweika
More informationSolutions of Equations in One Variable. FixedPoint Iteration II
Solutions of Equations in One Variable FixedPoint Iteration II Numerical Analysis (9th Edition) R L Burden & J D Faires Beamer Presentation Slides prepared by John Carroll Dublin City University c 2011
More information[2], [3], which realize a time bound of O(n. e(c + 1)).
SIAM J. COMPUT. Vol. 4, No. 1, March 1975 FINDING ALL THE ELEMENTARY CIRCUITS OF A DIRECTED GRAPH* DONALD B. JOHNSON Abstract. An algorithm is presented which finds all the elementary circuitsof a directed
More informationNCPC 2013 Presentation of solutions
NCPC 2013 Presentation of solutions Head of Jury: Lukáš Poláček 20131005 NCPC Jury authors Andreas Björklund (LTH) Jaap Eldering (Imperial) Daniel Espling (UMU) Christian Ledig (Imperial) Ulf Lundström
More informationMEP Pupil Text 12. A list of numbers which form a pattern is called a sequence. In this section, straightforward sequences are continued.
MEP Pupil Text Number Patterns. Simple Number Patterns A list of numbers which form a pattern is called a sequence. In this section, straightforward sequences are continued. Worked Example Write down the
More informationWhy you shouldn't use set (and what you should use instead) Matt Austern
Why you shouldn't use set (and what you should use instead) Matt Austern Everything in the standard C++ library is there for a reason, but it isn't always obvious what that reason is. The standard isn't
More information