{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

11-21 notes - distance d • Each vertex v at distance d is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
11/21/11 Algorithms and Data Structures Notes Graphs Matrix – stores left to right of a level, list – stores the adjacent parts of the tree on one node Matrix θ(1) edge lookup θ(n 2 ) List θ(n) θ(n+m) Lookup Pseudocode Claim: Very vertex of G is enqueued in strict order by its distance from s, w/ correct distance set at the time it is enqueued Pf: By induction on distance from s. Base : By inspection, s is enqueued first with correct distance of 0. Induction : Suppose claim holds for all vertices up to distance d-1. Then all vertices at distance u <= d-1 are enqueued before any vertex at distance d, w/ correct distance. By FIFO property of Q, all vertices at distance d-1 are dequeued before any vertices at
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: distance d. • Each vertex v at distance d is adjacent to some vertex w at distance d-1. • Hence, when expanding from w, we will see v. • If v is visited it must have been bound by some other w’ at distance d-1; else it is unvisited. • In either case we set v’s distance to d • Since no vertex at distance d is dequeued until all vertices at distance d-1 have been dequeued (by IH&FIFO), all verticeis at distance d will have been enqueued by the time last vertex at distance d-1 is processed. • Conclude that all verticies at dist d are enqueued before any vertex dist > d. Cost Initial: θ(n) Loop: θ(n) for enqueue, dequeue = = θ(m) Added all together gives us θ(n+m)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online