38 introduction to graphs
play

38: Introduction to Graphs Chris Wyatt Electrical and Computer - PowerPoint PPT Presentation

ECE 2574 Introduction to Data Structures and Algorithms 38: Introduction to Graphs Chris Wyatt Electrical and Computer Engineering Virginia Tech Graphs One can approach graphs from different perspectives 1) It is a data structure: extension


  1. ECE 2574 Introduction to Data Structures and Algorithms 38: Introduction to Graphs Chris Wyatt Electrical and Computer Engineering Virginia Tech

  2. Graphs One can approach graphs from different perspectives 1) It is a data structure: extension of trees 2) Is is a mathematical construct 3) A model of many different real world problems

  3. From trees to graphs Tree Graph

  4. Definition of a graph A graph is a collection of vertices (nodes), V, and a set of pairs of vertices, E. G = {V,E} Example: V = {a b c d} E = {(a,c) (c,b) (b,d) a b c d a and c are adjacent c a b d

  5. Terminology: Edges Edges may be order of vertex pairs undirected neglected or directed order of vertex pairs determines direction

  6. Terminology: graphs vs multi-graphs Graphs have at most one edge between two vertices V = {a b c d} E = {(a,c) (c,b) (b,d)} a b c d Multigraphs allow duplicate edges V = {a b c d} E = { (a,c) (c,b) (b,d) (a,c) } a b c d

  7. Terminology: subgraphs Any subset of V and E forms a subgraph a a i i c f b b Undirected Graph G A subgraph of G

  8. Terminology: subgraphs Any subset of V and E forms a subgraph a i c c f b f b Undirected Graph G Another subgraph of G

  9. Terminology: paths A path is a sequence of vertices connected by edges c d i b h l a j e g f k Paths may be directed or undirected

  10. Terminology: paths A path is a sequence of vertices connected by edges c d i b h l a j e g f k Paths may be directed or undirected

  11. Terminology: cycle A cycle is a path that starts and stops at the same vertex c d i b h l a j e g f k

  12. Terminology: cycle A cycle is a path that starts and stops at the same vertex c d i b h l a j e g f k

  13. Terminology: cycle A cycle is a path that starts and stops at the same vertex c d i b h l a j e g f k

  14. Terminology: connected / disconnected A graph is connected if every pair of vertices are connected by at least one path a k i c g f b d l

  15. Terminology: connected / disconnected Otherwise it is disconnected. a k i c g f b d l

  16. Vertices and Edges can have properties or attributes attached to them. Example: driving routes between cities Roanoke 7.86 miles 37.5 miles 15 min 40 min Blacksburg Christiansburg 14.3 miles 23 min 10 miles 17 min Radford 46.7 miles 53 min

  17. Vertices and Edges can have properties or attributes attached to them. Example: driving routes between cities 7.86 miles 15 min Blacksburg Christiansburg Name GPS coord length in miles Population driving time etc road type (2 lane, 4 lane, access controlled)

  18. A commonly encountered graph is one where the edge property is a weight . Weighted graphs (directed or undirected) have edges whose property is a cost. Often one want to find paths connecting nodes where some function of the sum of the weights is optimal a min or max). For example: what is the shortest route from Roanoke to Radford? what is the fastest? etc.

  19. Some categories of graphs Complete Random Planar

  20. Small-World Graphs Small world graphs often appear in the real world and have very interesting properties. • Seven degrees of Kevin Bacon • Large Scale Computer Networks • Brains Neural Connections in the worm C-elegans 279 vertices 6,417 edges

  21. Example uses of graphs Path planning Layout routing Games and puzzles Many kinds of circuits Networked systems Optimization Constraint Satisfaction Logical Inference Probabilistic Inference ..... on and on .....

  22. Implementing Graphs There is no graph data structure in the current standard C++ library. It is easy to roll your own using existing standard library containers. There is also the boost graph library (www.boost.org)

  23. Three common approaches to representing graphs. Adjacency matrix: given N vertices, the edges are indicated by an NxN matrix Adjacency List: given N vertices, the edges are indicated by a list of connected vertices for each vertex. Pointer based: given a pointer to a vertex, which contains pointers to it ’ s adjacent vertices

  24. Graph using an adjacency matrix a a b c d c a 0 1 0 1 b 1 0 0 0 c 0 1 0 1 d b d 0 0 0 0 - Undirected graphs have a symmetric matrix - Weighted graphs have integer or real entries

  25. Graph using an adjacency list a b d a c b a c b d d b d - the lists could be vectors, linked, or trees

  26. Graph using pointers root a c d b - graph must have a root and be connected. - Why?

  27. Advantages/Disadvantages of implementations Adjacency matrix Advantages 1. simple 2. space efficient for dense graphs (~ complete) 3. fast access to all edges Disadvantages 1. space inefficient for sparse graphs

  28. Advantages/Disadvantages of implementations Adjacency list Advantages 1. space efficient for sparse graphs Disadvantages 1. space inefficient for dense graphs 2. access to arbitrary edges slower

  29. Advantages/Disadvantages of implementations Pointer based Advantages 1. space efficient for sparse graphs Disadvantages 1. space inefficient for dense graphs 2. access to arbitrary edges slower 3. cannot represent disconnected graphs (easily)

  30. Next Actions and Reminders Read CH pp. 614-630 on graph traversals and algorithms Program 5 is due 12/11 Please Fill out the SPOT survey!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend