Lecture 16 - Graphs

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

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

Wednesday, March 14th    Intro to Graphs Graph Traversals Dijkstra’s Algorithm Final Exam: Saturday, June 17th 3:00pm-6:00pm   Final Exam Location: TBA

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

View Full Document
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. ..
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.

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

View Full Document
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.
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.

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

View Full Document
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.
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

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

View Full Document
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
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

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

View Full Document
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!
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
Ask a homework question - tutors are online