Lecture 16 - Graphs

Lecture 16 - Graphs - Wednesday,March14th IntrotoGraphs...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Wednesday, March 14th    Intro to Graphs Graph Traversals Dijkstra’s Algorithm Final Exam: Saturday, June 17th 3:00pm-6:00pm   Final Exam Location: TBA
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Graphs A graph is a finite set of dots called vertices (or nodes) connected by links called edges (or arcs). A given  vertex  can have multiple edges to other vertices. A given  edge  may be connected to at most two vertices. Question : When can an edge have only one vertex? Each vertex in the graph can hold  any type of data. ..
Background image of page 2
Directed vs. Undirected Graphs In a  directed graph , an edge goes from one vertex to another in a  specific direction For example, above we have an edge that goes from 2 to 1, but not the other way around.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Directed vs. Undirected Graphs In an  undirected graph , all edges are bi-directional.      You can go either way along any edge.   For example, we can get from 2 to 4, and back from 4 to 2 along the same edge.
Background image of page 4
Graph Terminology A path :  A path is a sequence of adjacent vertices. U V W X Y Here’s a path from U to W.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Representing a Graph in Your  Programs The easiest way to represent a graph is with a  double-dimensional array . The  size  of each dimension of the array is equal to the  number of vertices  in the graph.  bool graph[5][5];   Each element in the array indicates whether or not there is an edge between vertex i and vertex j. 
Background image of page 6
Each element in the array indicates whether or not there is an edge between vertex i and vertex j.  Representing a Graph in Your  Programs bool graph[5][5];   0 1 2 3 4 graph[0][3] = true; graph[1][2] = true; graph[3][0] = true; // edge from node 0 to node 3 This is called an  adjacency matrix
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Representing a Graph in Your  Programs Exercise : What does the following directed graph look like?  Nodes 0 1 2 3 0 True False True False 1 True False False False 2 False False  False True 3 True False True false Question: How do you represent the following undirected graph with an adjacency matrix? 0 1 2 3
Background image of page 8
An Interesting Property of Adjacency Matrices Consider the following graph: And it’s associated A.M.: Joe Mary Tsuen Lily Neato effect : If you multiply the matrix by itself  something cool happens! 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 0 0 X                = Joe Mary Lily M a r y L i l 0 1 0 0 0 0 1 0 0 0 0 1 J o e T s u n Joe Mary Lily 0 0 1 0 0 0 0 1 0 1 0 0 0 0 1 0 The resulting matrix shows us which vertices are exactly  two edges  apart. 1 1
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Joe Mary Tsuen Lily M a r y L i l 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 J o e T s u n An Interesting Property of Adjacency Matrices Consider the following graph: And it’s associated A.M.: Joe Mary Lily Neato effect : If you multiply the matrix by itself  something cool happens!
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/02/2012 for the course COMPUTER S 32 taught by Professor Smallberg during the Winter '12 term at UCLA.

Page1 / 39

Lecture 16 - Graphs - Wednesday,March14th IntrotoGraphs...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online