Algorithms on graphs Algorithms on graphs Computational Science and Engineering Outlines • Graph revisit • Topological sorting • Minimum spanning trees 2 Graphs • A graph is a pair (V, E), where – V i[.]
Algorithms on graphs Computational Science and Engineering Outlines • Graph revisit • Topological sorting • Minimum spanning trees Graphs • A graph is a pair (V, E), where – V is a set of nodes, called vertices – E is a collection of pairs of vertices, called edges – Vertices and edges are positions and store elements • Example: 33 HNL 255 LAX 123 80 – A vertex represents an airport and stores the three-letter airport code – An edge represents a flight route between two airports and 84 PVD stores the mileage of the routeOR 18 D 14 SFO DF W LGA 138 11 10 9 MIA Travel on graphs BFS DFS 1 10 1 12 10 11 Topological Sorting • Number vertices, so that (u,v) in E implies A typical student u < v wake up day study computer sci nap pla y eat write c.s program make cookies for professors sleep0 more c.s work out 1 dream about graphs Naïve algorithms Method TopologicalSort(G) H ← G // Temporary copy of G n ← G.numVertices() while H is not empty for each vertex v if v be a vertex with no outgoing edges then Label v ← n n←n-1 Remove v from H Complexity: O(n3) Naïve algorithms wake up study computer sci eat nap pla y more c.s write c.s program work out make cookies for professors sleep 1 dream about graphs Naïve algorithms wake up study computer sci eat nap pla y more c.s write c.s program work out make cookies for professors 10 sleep Naïve algorithms wake up study computer sci eat nap pla y more c.s write c.s program work out make cookies for professors Naïve algorithms wake up study computer sci nap pla y eat write c.s program make cookies for professors sleep0 more c.s work out 1 dream about graphs