Tables 1.9 - Correctness: Formal Proof Output: d [v ] =...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Correctness: Formal Proof Output: d [v ] = distance (v) from s to v , v V . [v ] = u such that (u, v ) is last edge on shortest path from s to v . Two-step proof: On exit: CSE 2011 Prof. J. Elder - 156 - Last Updated: 4/1/10 10:16 AM s u CSE 2011 Prof. J. Elder - 157 - v Last Updated: 4/1/10 10:16 AM BFS(G,s) Precondition: G is a graph, s is a vertex in G Postcondition: d [u ] = shortest distance [u ] and [u] = predecessor of u on shortest paths from s to each vertex u in G for each vertex u V [G] d [u ] s [u ] null color[u] = BLACK //initialize vertex colour[s] RED u v d [s ] 0 Q.enqueue(s ) while Q u Q.dequeue() for each v Adj[u ] //explore edge (u,v ) if color[v ] = BLACK colour[v] RED d [v ] d [u ] + 1 colour [u ] CSE 2011 Prof. J. Elder [v ] u Q.enqueue(v ) GRAY - 158 - Last Updated: 4/1/10 10:16 AM s x u v Contradiction! CSE 2011 Prof. J. Elder - 159 - Last Updated: 4/1/10 10:16 AM Correctness CSE 2011 Prof. J. Elder - 160 - Last Updated: 4/1/10 10:16 AM ...
View Full Document

Page1 / 5

Tables 1.9 - Correctness: Formal Proof Output: d [v ] =...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online