CS Notes 15

CS Notes 15 - o USE A STACK/RECURSION o Basic operations?...

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

View Full Document Right Arrow Icon
Data structure to map vertex names to numbers 1. Arrays o Vertex num->name O(1) o Vertex name-> num Worst case O(n) Sequential search 1. Hash table o Hash on vertex name o (Key,value)=(String,int) o Vertex num->name Can't do. Not efficient to dump and search o Vertex name->num Expected O(n) Must use both array and Hash table o Array to access names from nums o Hash table to access ums from names Graph Traversal (mapping/tracing topology) 1. Depth-first search (DFS) o Start at any arbitrary vertex and go down until you can not go any further, then go back and continue down another path o When a vertex is visited, it is marked as such in a Boolean array
Background image of page 1

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

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

Unformatted text preview: o USE A STACK/RECURSION o Basic operations? • Visiting O(1) Do this n times • Checking if a neighbor is visited O(1) Directed: do this e times Undirected: do this 2e times • Run time: O(n+e) 1. Breadth-first search (BFS) o Enqueue root o Visit the children of the root, add children to queue o Dequeue-> this is new root o Repeat until queue is empty && all nodes visited o Basic operations • Visiting n • Check neighbor Directed: e Undirected: 2e • Enqueue n • Dequeue n o Runtime: O(n+e)...
View Full Document

This note was uploaded on 02/29/2012 for the course 198 112 taught by Professor Venugopal during the Spring '09 term at Rutgers.

Page1 / 2

CS Notes 15 - o USE A STACK/RECURSION o Basic operations?...

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

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