2c03-review - 00078

2c03-review - 00078 - i do if mark[w] = 0 then begin...

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

View Full Document Right Arrow Icon
5 7.[20] A root of a directed acyclic graph (dag) is a vertex r such that every vertex of the dag can be reached by a directed path from r. Write a program to determine whether a dag is rooted. Assume that the dag is represented using adjacency lists. Make sure that your running time is linear in the number of edges. Let us define a source vertex as one without incoming arcs. Now a dag is rooted if and only if it has exactly one source vertex. The algorithm scans the adjacency lists, and checks how many vertices have no incoming arcs. A possible pseudo-code program: count = n for i = 1 to n for each vertex w on the adjacency list of v
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i do if mark[w] = 0 then begin mark[w]=1; count=count-1 e n d if count = 1 then print(YES) else print(NO) 8.[10] Sort the below graph topologically. Illustrate all major steps. A solution at the end 9.[40] In the graph from Question 4 replace arrows by lines, i.e. translate it into a graph which is indirected. Assume ordering as in 4.b. a.[10] Find a minimum-cost spanning tree by Prims algorithm. b.[10] Find a minimum-cost spanning tree by Kruskals algorithm. c.[10] Find a depth-first spanning tree starting at a. d.[10] Find a breadth-first spanning tree starting at a. Give all steps. Solutions at the end...
View Full Document

This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.

Ask a homework question - tutors are online