![]() |
![]() |
|
home—info—lectures—exams—archive
[We'll talk about FSMs on Wednesday; you can work on the first and last problems before then.] We saw def'n of graphs, and things that a graph can represent. Def'n: Tree: An undirected (connected) graph with no cycles. Some standard problems: - searching (DFS, BFS) - 4-coloring, k-coloring (register allocation) - weighted graphs: shortest path (Dijkstra is modified BFS) minimum spanning tree
// Depth-first search: Set seen = new Set(); Stack pending = new Stack(); pending.push(V.get(0)); while (!pending.isEmpty()) { Vertex curr = pending.pop(); if (!seen.contains(curr)) { // This test not needed for trees! seen.add(curr); System.out.println( "Processing "+ curr.toString() + " (in pre-order)" ); for ( Vertex nhbr : curr.getNeighbors() ) { pending.add(nhbr); } } |
home—info—lectures—exams—archive
©2008, Ian Barland, Radford University Last modified 2008.Dec.12 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |