
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Department of Computer Science University of Maryland, College Park
Many-to-many relationship between elements Each element has multiple predecessors Each element has multiple successors
Directed graph Directed edges Undirected graph Undirected edges
Weighted graph Weight (cost) associated with each edge
Cycle Path that ends back at starting node Example A, E, A A, B, C, D, E, A Simple path No cycles in path Acyclic graph No cycles in graph
Reachable Path exists between nodes Connected graph Every node is reachable from some node in graph Unconnected graphs
Approach Visit all neighbors of node first View as series of expanding circles Keep list of nodes to visit in queue Example traversal
Example traversals starting from 1 1 2 3 4 5 6 7
Left to right Right to left Random
Approach Visit all nodes on path first Backtrack when path ends Keep list of nodes to visit in a stack Example traversal
Example traversals from 1 (preorder) 1 2 6 3 5 7 4
Left to right Right to left Random
Record set of visited nodes Initialize { Visited } to empty set Add to { Visited } as nodes is visited Skip nodes already in { Visited } 1 2 3 4 V = ∅
Mark nodes as visited Initialize tag on all nodes (to False) Set tag (to True) as node is visited Skip nodes with tag = True F F F F
for all nodes X set X.tag = False { Discovered } = { 1st node } while ( { Discovered } ≠ ∅ ) take node X out of { Discovered } if (X.tag = False) set X.tag = True for each successor Y of X if (Y.tag = False) add Y to { Discovered }
Order nodes taken out of { Discovered } key Implement { Discovered } as Queue First in, first out Traverse nodes breadth first Implement { Discovered } as Stack First in, last out Traverse nodes depth first