Slides - Graphs

Slides - Graphs - // Process the keys of the graph in...

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

View Full Document Right Arrow Icon
1 Graphs Depth-First Search - DFS Algorithm depthFirst (graph) // Process the keys of the graph in depth-first order. if (empty graph) return set walkPtr to graph first loop (through all vertices) set processed to 0 end loop createStack (stack) loop (through vertex list) if (vertex not processed and not in stack) pushStack (stack, walkPtr) set walkPtr processed to 1 end if
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 loop (not emptyStack(stack)) set vertex to popStack(stack) process (vertex) set vertex to processed loop (through arc list) if (arc destination not in stack) pushStack(stack, destination) set destination to in stack end if get next destination end loop end loop end if get next vertex end loop destroyStack(stack) // end dapthFirst
Background image of page 2
3 Breadth-First Search – BFS Algorithm breadthFirst (graph)
Background image of page 3

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

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

Unformatted text preview: // Process the keys of the graph in breadth-first order. if (empty graph) return end if createQueue (queue) loop (through all vertices) set vertex to not processed end loop loop (through all vertices) if (vertex not processed) if (vertex not in queue) enqueue (queue, walkPtr) set vertex to enqueued end if 4 loop (not emptyQueue (queue)) set vertex to dequeue (queue) process (vertex) set vertex to processed loop (through adjacency list) if (destination not enqueued or processed) enqueue (queue, destination) set destination to enqueued end if get next destination end loop end loop end if get next vertex end loop destroyQueue (queue) // end breadthFirst...
View Full Document

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 4

Slides - Graphs - // Process the keys of the graph in...

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

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