Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS112 Lab 11, April 15, 2010 Diane H. Theriault

Similar presentations


Presentation on theme: "CS112 Lab 11, April 15, 2010 Diane H. Theriault"— Presentation transcript:

1 CS112 Lab 11, April 15, 2010 http://cs-people.bu.edu/deht/cs112_spring11/lab11/ Diane H. Theriault deht@cs.bu.edu http://cs-people.bu.edu/deht/

2 Graphs You can’t throw a rock in Computer Science without hitting a graph Vertexes: the things in the graph Edges: the relationships/connectivity between things. G = (V,E) (Graph = (Vertexes, Edges))

3 Graph Implementations Adjacency lists – Each node has a list of other nodes it is connected to. (alternatives) – Adjacency matrix – Edge List

4 Constructing a Graph (Implementation) (Go through code on p. 432 for reading in a graph from a file.) http://algs4.cs.princeton.edu/41undirected/G raph.java.html http://algs4.cs.princeton.edu/41undirected/G raph.java.html

5 Traversals Most of the interesting things about graphs are tied up in how the nodes are connected to each other Techniques for walking through graphs: – Depth-first traversal – Breadth-first traversal

6 Depth-First Traversal (p. 437) Stack-based (recursive) (Example) http://algs4.cs.princeton.edu/41undirected/D epthFirstSearch.java.html http://algs4.cs.princeton.edu/41undirected/D epthFirstSearch.java.html

7 Breadth-First Traversal (p. 446) Queue-based (Example) http://algs4.cs.princeton.edu/41undirected/Br eadthFirstPaths.java.html http://algs4.cs.princeton.edu/41undirected/Br eadthFirstPaths.java.html


Download ppt "CS112 Lab 11, April 15, 2010 Diane H. Theriault"

Similar presentations


Ads by Google