{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2c03-review - 00084

# 2c03-review - 00084 - directed graph Assume that the cost...

This preview shows page 1. Sign up to view the full content.

SE2C03. Sample solutions to the assignment 5. Total of this assignment is 75pts. 100% equals 65. Each assignment is worth 5%. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit to me during class, office hours, or just slip under the door to my office. Solutions to all questions except #5 start from next page. 1.[10] 2.[10] 3.[10] 4.[5] 5.[10] A simple cycle in a given graph (V,E), is a sequence of vertices: v 1 , v 2 , ... , v n , such that (v i ,v i+1 ) in E for i=1,...,n-1, v 1 = v n , and v i v j for i j and i 1, j n (i.e. all vertices different). Modify Floyd’s algorithm (for the all-pairs shortest path problem) to find a minimum-cost simple cycle in a weighted
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: directed graph. Assume that the cost adjacency matrix of the digraph is given. The algorithm should run in O(n 3 ) time. A possible solution: Procedure Cycle( G=(V,E)) for each vertex v in V do mark[v]:=unvisited; for each vertex v in V do if mark[v]=unvisited then Cycle1(V,null); Procedure Cycle1(V,p) {p is the parent of v in the DFS tree} mark[v]:=visited; for each vertex w adjacent to v do if mark[w]=unvisited then Cycle1(V,w) e l s e i f w ≠ p then begin print(“cycle exists”); exit end Hence for a matrix representation we have O(n 3 ), however we can do better if G is represented as adjacency list (as in DSF). Then the algorithm checks at most n edges, so time is O(2n)=O(n). 6.[10] 7.[10] 8.[10]...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern