1 / 22

Chapter 9: Graphs

Mark Allen Weiss: Data Structures and Algorithm Analysis in Java. Chapter 9: Graphs. Basic Concepts. Lydia Sinapova, Simpson College. Graphs – Basic Concepts. Basic definitions: vertices and edges More definitions: paths, simple paths, cycles, loops Connected and disconnected graphs

emily
Télécharger la présentation

Chapter 9: Graphs

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. Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Chapter 9: Graphs Basic Concepts Lydia Sinapova, Simpson College

  2. Graphs – Basic Concepts • Basic definitions: vertices and edges • More definitions: paths, simple paths, cycles, loops • Connected and disconnected graphs • Spanning trees • Complete graphs • Weighted graphs and networks • Graph representation • Adjacency matrix • Adjacency lists

  3. Basic Graph Definitions A graph is a mathematical object that is used to model different situations – objects and processes: Linked list Tree (partial instance of graph) Flowchart of a program City map Electric circuits Course curriculum

  4. Vertices and Edges Definition:A graph is a collection (nonempty set) of vertices and edges Vertices:can have names and properties Edges:connect two vertices, can be labeled, can be directed Adjacent vertices:there is an edge between them

  5. A B C D C A B D Example Graph1 Vertices: A,B,C,D Edges: AB, AC, BC, CD Two ways to draw the same graph

  6. A B C D A B C D Directed and undirected graphs Graph2 Graph3 These are two different graphs

  7. A B C D More definitions : Path A list of vertices in which successive vertices are connected by edges A B C B A C D A B C A B C A B C D B A B A C

  8. A B C D More definitions : Simple Path No vertex is repeated. A B C D D C A D C B A B A B C

  9. A B C D More definitions : Cycle Simple path with distinct edges, except that the first vertex is equal to the last A B C A B A C B C B A C A graph without cycles is calledacyclic graph.

  10. A B C D More definitions : Loop An edge that connects the vertex with itself

  11. A B A B C C D D Connected and Disconnected graphs Connected graph: There is a path between each two vertices Disconnected graph : There are at least two vertices not connected by a path. Examples of disconnected graphs:

  12. A B C D E Graphs and Trees Tree:an undirected graph with no cycles, and a node chosen to be the root Source graph:

  13. C A B E D A C E B D Graphs and Trees Tree1: root A Tree2: root C

  14. A B C D A spanning tree of an undirected graph A sub-graph that contains all the vertices, and no cycles.If we add any edge to the spanning tree, it forms a cycle, and the tree becomes a graph A B graph spanning tree C D

  15. A B C D A A B B C C D D Examples All spanning trees of the graph on the previous slide

  16. A B C D E Complete graphs Graphs with all edges present – each vertex is connected to all other vertices Dense graphs: relatively few of the possible edges are missing Sparse graphs: relatively few of the possible edges are present A complete graph

  17. Weighted graphs and Networks Weighted graphs – weights are assigned to each edge (e.g. road map) Networks:directed weighted graphs (some theories allow networks to be undirected) B 2 1 C A 2 4 3 D

  18. Graph Representation • Adjacency matrix • Adjacency lists

  19. Adjacency matrix – undirected graphs Vertices: A,B,C,D Edges: AC, AB, AD, BD A B C D   A 0 1 1 1 B 1 0 0 1 C 1 0 0 1 D 1 1 0 0 The matrix is symmetrical A B C D

  20. Adjacency matrix – directed graphs Vertices: A,B,C,D Edges: AC, AB, BD, DA A B C D  A 0 1 10 B 0 0 0 1 C 0 0 0 0 D 10 0 0 A B C D

  21. Adjacency lists – undirected graphs Vertices: A,B,C,D Edges: AC, AB, AD, BD Heads lists A B C D B A D C A D A B A B C D

  22. Adjacency lists – directed graphs Vertices: A,B,C,D Edges: AC, AB, BD, DA Heads lists A B C B D C = D A A B C D

More Related