Presentation is loading. Please wait. # Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.

## Presentation on theme: "Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1."— Presentation transcript:

Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1

2 4.3 Shortest Paths & Distance Traversal: process visiting every vertex Tree or Graph Is a traversal necessary to solve a particular problem? Breadth-first vs Depth-first searches & traversals Distance between 2 vertices: number of edges on the shortest path between 2 vertices (may be more than one path)

3 Shortest Paths & Distance Traversal Distance Breadth-first Depth-first

4 Finding Distances – Breadth-first PROBLEM: Find distance between vertex A and all other vertices in the graph Notation: Vertex label 4(F) means distance from A to current vertex is distance 4 and predecessor node on the path is F Let A be vertex 1 Label on vertex 4 is 2(5)

5 Finding Distances – Breadth-first PROBLEM: Find distance between vertex A and all other vertices in the graph Choose start vertex 1 – label 0(-) Label all vertices adjacent to vertex 1 Repeat for newly labeled vertices (never change label on vertex) Continue until all vertices are labeled.

6 Breadth-First Search Algorithm Page 183 Complexity Process each vertex & edge once  v + e ops Remember: e <= C(v,2) = (v (v-1))/2 - - Why? v + (v (v-1))/2  O(v 2 )

7 Weighted Graphs Graph in which a number = weight is assigned to each edge Weight of Path: sum of edges in path Used in MANY applications Distance, Cost, Size Shortest Path Problems

8 Dijkstra’s Algorithm Finds shortest path between a designated vertex S & all other vertices in graph & provides actual shortest paths Overview: Start at S Find nodes adjacent Each step update with shorter path, if available

9 Dijkstra’s Algorithm - Overview 10 3 5 1 4 S A B C

Number of Paths Theorem 4.7 (unweighted graph) For a graph G with vertices V1, V2,…Vn & adjacency matrix A, the number of paths of length m from Vi to Vj is the (i, j) entry of A m. See example on page 189-190 Review Matrix Multiplication!!

11 Flubber Graphs Named after a professor who developed in 1960’s Not in our book Flubber Graph: A graph (set of vertices & edges) in which each vertex is flubberized.

12 Homework Section 4.3 – pages 190-193 Exercises – All 1 – 16, 20 1 – 4, Breadth-first algorithm, 5 – 8, Dijkstra’s Algorithm 9 – 12, modified Dijkstra’s, 13 – 16, Theorem 4.7

13 Graph Definitions Flubber Graph A graph in which each vertex is flubberized Connected Graph A graph in which each vertex is connected

14 Graph Definitions Flubber Graph A graph in which each vertex is flubberized A graph in which each vertex is flubberized with every other vertex Connected Graph A graph in which each vertex is connected A graph in which each vertex is connected to every other vertex

15 4.4 Coloring a Graph Omit section but define problem

16 4.5 Directed Graphs - Multigraphs Directed Graph: finite, non-empty set V and E (vertices & edges) in which each edge has specified direction between vertices Directed Edge: An edge (A,B) is from vertex A to B, but not vice versa Degree In degree: # of edges directed into a vertex Out degree: # of edges directed from a vertex

17 Representation of Directed Graphs Adjacency Matrix: works but matrix is not symmetrical Adjacency List: also works Directed Graph with weighted edges Must also store the weights Multigraph Parallel Directed Edges: Represent? Loop: Represent?

18 Paths in Directed Graphs Directed Path: sequence of edges from vertex A to B, following edge direction Length of Path: number of edges on path Simple Directed Path: No repeated vertices Directed cycle Strongly Connected: A directed multigraph which contains a path from vertex A to B for every pair of vertices Means A to B & B to A

19 Homework Section 4.5 – Pages 212 – 218 Exercises 1 – 22, 24, 25, 35-37, 74,77 Maybe others later – or just try some others Omit from study pp. 208-212

Download ppt "Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1."

Similar presentations

Ads by Google