22.02.2014 Views

Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet

Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet

Discrete Mathematics University of Kentucky CS 275 Spring ... - MGNet

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

procedure depth_first( G = (V,E): connected graph )<br />

T := tree with only some single v,V<br />

visit( v, T )<br />

{ T is a spanning tree. }<br />

procedure breadth_first( G = (V,E): connected graph )<br />

T := tree with only some single v,V<br />

L := v<br />

while L - /<br />

Remove first vertex v,L<br />

for each neighbor w,V <strong>of</strong> v<br />

if w6L and w6T then<br />

Add w to the end <strong>of</strong> L<br />

Add w and edge {v,w} to T<br />

{ T is a spanning tree. }<br />

207<br />

Theorem: Let G = (V,E) be a connected graph with |V| = n. Then either depth<br />

first or breadth first takes O(e), or O(n 2 ), steps to construct a spanning tree.<br />

Pro<strong>of</strong>: For a simple graph, |E| ; n(n41)/2.<br />

Bactracking applications:<br />

• Graph coloring: can a graph be colored in n colors<br />

• n-Queens problem: find places on a n$n board so n queens are toothless<br />

n<br />

! $<br />

• Sums <strong>of</strong> subsets: Given " x<br />

# i<br />

% , where xi ,N, find a subset whose sum is M<br />

&i=1<br />

• Web crawlers: search all hyperlinks on a network efficiently<br />

208

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!