{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Graphs 1.5

# Graphs 1.5 - Adjacency Matrix Structure Edge list structure...

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Adjacency Matrix Structure Edge list structure Augmented vertex objects a v b u Integer key (index) associated with vertex w 2D-array adjacency array Reference to edge object for adjacent vertices 0 u 1 0 Null for nonnonadjacent vertices 0 a CSE 2011 Prof. J. Elder - 21 - 2 1 Ø 1 2 v w 2 Ø Ø Ø Ø b Last Updated: 4/1/10 10:16 AM Asymptotic Performance (assuming collections V and E represented as doubly-linked lists) |V| vertices, |E| edges no parallel edges no self-loops Bounds are “big-Oh” Edge List Adjacency List Adjacency Matrix Space |V|+|E| |V|+|E| |V|2 incidentEdges(v) areAdjacent (v, w) insertVertex(o) |E| |E| 1 deg(v) min(deg(v), deg(w)) 1 |V| 1 |V|2 insertEdge(v, w, o) 1 1 1 |E| deg(v) |V|2 1 1 1 removeVertex(v) removeEdge(e) CSE 2011 Prof. J. Elder - 22 - Last Updated: 4/1/10 10:16 AM Graph Search Algorithms CSE 2011 Prof. J. Elder - 23 - Last Updated: 4/1/10 10:16 AM Depth First Search (DFS) Idea: Continue searching “deeper” into the graph, until we get stuck. If all the edges leaving v have been explored we “backtrack” to the vertex from which v was discovered. Analogous to Euler tour for trees Used to help solve many graph problems, including Nodes that are reachable from a specific node v Topological sorts Detection of cycles Extraction of strongly connected components CSE 2011 Prof. J. Elder - 24 - Last Updated: 4/1/10 10:16 AM Depth-First Search The DFS algorithm is similar to a classic strategy for exploring a maze We mark each intersection, corner and dead end (vertex) visited We mark each corridor (edge ) traversed We keep track of the path back to the entrance (start vertex) by means of a rope (recursion stack) CSE 2011 Prof. J. Elder - 25 - Last Updated: 4/1/10 10:16 AM ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online