Download presentation
Presentation is loading. Please wait.
1
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections
2
Graph Representations How do we represent a graph? A B E D C
3
List Structures V = {A, B, C, D, E} E = {{A, B}, {A, D}, {C, E}, {D, E}} Incidence List –E = {{A, B}, {A, D}, {C, E}, {D, E}} Adjacency List –L = [A={B, D}, B={A}, C={E}, D={A, E}, E={C, D}] A B E D C
4
Matrix Structures V = {A, B, C, D, E} E = {{A, B}, {A, D}, {C, E}, {D, E}} Adjacency Matrix A B E D C ABCDE A11010 B11000 C00101 D10011 E00111
5
A Directed Graph V = {A, B, C, D, E} E = {(A, B), (B, A), (B, E), (D, A), (E, A), (E, D), (E, C)}
6
Weighted Graph ABCD A0260 148 B2600 C 0 D148 0
7
Disconnected Graph
8
Equivalence of Graphs The numbering of the vertices, and their physical arrangement are not important. The following is the same graph as the previous slide.
9
Path Definition Adjacency Path –A sequence of vertices in which each successive vertex is adjacent to its predecessor Connected Graph –A path from every vertex to every other vertex Fully Connected Graph –Every vertex is adjacent to every other vertex
10
Example of a Path
11
Example of a Cycle
12
Relationship Between Graphs and Trees A tree is a special case of a graph. Any connected graph which does not contain cycles can be considered a tree. Any node can be chosen to be the root.
13
What kinds of things do we do with graphs?
14
Breadth First Search Starting at a source vertex Systematically explore the edges to “discover” every vertex reachable from s. Produces a “breadth-first tree” –Root of s –Contains all vertices reachable from s –Path from s to v is the shortest path
15
Algorithm 1.Take a start vertex, mark it identified (color it gray), and place it into a queue. 2.While the queue is not empty 1.Take a vertex, u, out of the queue (Begin visiting u) 2.For all vertices v, adjacent to u, 1.If v has not been identified or visited 1.Mark it identified (color it gray) 2.Place it into the queue 3.Add edge u, v to the Breadth First Search Tree 3.We are now done visiting u (color it black)
16
Example
18
Trace of Breadth First Search
19
Breadth-First Search Tree
20
Maze as a Graph
21
Breadth First Search Tree
22
Maze Solution
23
Find all intersections
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.