1 / 7

CS112 Lab 11, April 15, 2010 cs-people.bu/deht/cs112_spring11/lab11/

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/. Graphs. You can’t throw a rock in Computer Science without hitting a graph Vertexes: the things in the graph

sonja
Download Presentation

CS112 Lab 11, April 15, 2010 cs-people.bu/deht/cs112_spring11/lab11/

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS112 Lab 11, April 15, 2010http://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/Graph.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/DepthFirstSearch.java.html

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

More Related