This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: BreadthFirst Search Input G ( V, E ) [a connected graph] v [start vertex] Algorithm BreadthFirst Search visit v V ← { v } [ V is the vertices already visited] Put v on Q [ Q is a queue] repeat while Q 6 = ∅ u ← head ( Q ) [ head ( Q ) is the first item on Q ] for w ∈ A ( u ) [ A ( u ) = { w { u, w } ∈ E } ] if w / ∈ V then visit w Put w on Q V ← V ∪ { w } endif endfor Delete u from Q The BFS algorithm basically finds a tree embedded in the graph. • This is called the BFS search tree 1 BFS and Shortest Length Paths If all edges have equal length, we can extend this algo rithm to find the shortest path length from v to any other vertex: • Store the path length with each node when you add it. • Length( v ) = 0. • Length( w ) = Length( u ) + 1 With a little more work, can actually output the shortest path from u to v . • This is an example of how BFS and DFS arise unex pectedly in a number of applications. ◦ We’ll see a few more 2 DepthFirst Search Input G ( V, E ) [a connected graph] v [start vertex] Algorithm DepthFirst Search visit v V ← { v } [ V is the vertices already visited] Put v on S [ S is a stack] u ← v repeat while S 6 = ∅ if A ( u ) V 6 = ∅ then Choose w ∈ A ( u ) V visit w V = V ∪ { w } Put w on stack u ← w else u ← top ( S ) [Pop the stack] endif endrepeat DFS uses backtracking • Go as far as you can until you get stuck • Then go back to the first point you had an untried choice 3 Spanning Trees A spanning tree of a connected graph G ( V, E ) is a con nected acyclic subgraph of G , which includes all the ver tices in V and only (some) edges from E . Think of a spanning tree as a “backbone”; a minimal set of edges that will let you get everywhere in a graph. • Technically, a spanning tree isn’t a tree, because it isn’t directed. The BFS search tree and the DFS search tree are both spanning trees. • In the text, they give algorithms to produce minimum weight spanning trees • That’s done in CS 482, so we won’t do it here. 4 Graph Coloring How many colors do you need to color the vertices of a graph so that no two adjacent vertices have the same color? • Application: scheduling ◦ Vertices of the graph are courses ◦ Two courses taught by same prof are joined by edge ◦ Colors are possible times class can be taught. Lots of similar applications: • E.g. assigning wavelengths to cell phone conversations to avoid interference. ◦ Vertices are conversations ◦ Edges between “nearby” conversations ◦ Colors are wavelengths. • Scheduling final exams ◦ Vertices are courses ◦ Edges between courses with overlapping enrollment ◦ Colors are exam times. 5 Chromatic Number The chromatic number of a graph G , written χ ( G ), is the smallest number of colors needed to color it so that no two adjacent vertices have the same color....
View
Full Document
 Spring '07
 SELMAN
 Graph Theory, vertices, bipartite graphs

Click to edit the document details