MC 302 Graph Theory Tuesday, 112304 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

MC 302 Graph Theory Tuesday, 112304

Description:

7.3: 1, 7ab (Modify Mathematica file) ... Cool Property of the Adjacency Matrix ... Cool observation: Entry bij = number of walks of length 2 from vi to vj! ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 10
Provided by: Mathematic53
Learn more at: http://www.skidmore.edu
Category:
Tags: cool | graph | theory | tuesday

less

Transcript and Presenter's Notes

Title: MC 302 Graph Theory Tuesday, 112304


1
MC 302 Graph TheoryTuesday, 11/23/04
  • Today
  • Graph representation and algorithms
  • Do Worksheet 9
  • Adjacency matrices and counting walks
  • Graph Searching DFS and BFS
  • Todays reading exercises
  • 7.3 1, 7ab (Modify Mathematica file)
  • 8.1 9 (both BFS and DFS vertices are visited
    alphabetically)

2
Cool Property of the Adjacency Matrix
  • If A aij is the adjacency matrix, then aij
    1 iff vi and vj are adjacent.
  • Equivalently, aij 1 iff there is a walk of
    length 1 from vi to vj. (Remember Length of a
    walk is the of edges.)
  • Let bij ai1a1j ai2a2j ainanj
  • bij obtained by multiplying corresponding entries
    of row i and column j.
  • Matrix B bij is called the A x A, or A2.
  • Cool observation Entry bij number of walks of
    length 2 from vi to vj!

3
Counting Walks with the Adjacency Matrix
A
  • Theorem. If A is the adjacency matrix of G, then
    entry i, j of Ak equals the number of walks of
    length k from vi to vj.
  • Proof. By induction (see text).
  • Example See MC302041123.nb

A3
A2
A3
4
Graph Searching
  • Many graph theory questions can be answered by
    doing an organized traversal of the graph.
  • The two main graph search algorithms
  • Depth-first Search
  • Breadth-first Search.

5
Depth-First Search
  • Basic Idea
  • Travel as far as you can from the starting vertex
    to new vertices
  • When you cant travel any further, back up along
    path to first vertex adjacent to a new vertex.
  • Repeat until all vertices have been visited.
  • Result of DFS
  • Every edge of G is labeled as either a tree
    edge or a back edge.
  • If G is connected, the tree edges form a spanning
    tree called a depth-first spanning tree.
    (Otherwise they form a spanning forest).

6
Depth-First Search Algorithm
  • Label all vertices and edges with label
    unvisited.
  • Pick arbitrary vertex v and label it visited.
  • If v has an unvisited neighbor w, label w
    visited and label edge v-w tree edge. Well
    also call v the parent of w. Replace v by w and
    repeat this step. Else go to next step.
  • If all vs neighbors are visited, label any
    unvisited incident edges back edges. If v has a
    parent x, replace v by x and go to previous step.
    Else go to next step.
  • If any vertex y is unvisited, label y visited,
    and go to step 3. Otherwise, algorithm is
    completed.

7
Properties of Depth-First Search
  • If implemented with adjacency matrix, runs in
    time O(n2)
  • If implemented with adjacency list, runs in time
    O(n e)
  • In general, runs in time proportional to size of
    data structure used to represent graph
  • Can be used for Finding spanning forest cycle
    detection finding path between vertices u and v
    testing for connectedness testing bipartiteness
    bridge detection cut point detection

8
Breadth-First Search
  • Basic Idea
  • Visit an initial vertex v, then visit all of its
    neighbors.
  • Repeat this with each neighbor of v, until all
    vertices have been visited
  • Result of BFS
  • If G is connected, the tree edges form a spanning
    tree called a breadth-first spanning tree.
    (Otherwise they form a spanning forest).
  • If v is the root of a BFS spanning tree T, then
    the path from v to w in T is a shortest path from
    v to w in G.

9
Breadth-First Search Algorithm and Properties
  • Algorithm
  • Pick arbitrary vertex v and number it vertex 1.
    Set count 1, current 1.
  • For each unnumbered neighbor w of v, increment
    count and assign that number to w. Assign label
    tree edge to edge v-w.
  • If count n, algorithm terminates. Otherwise,
    increment current and repeat from step 2.
  • Same complexity as DFS.
  • Can be used for Shortest path between u and v
    single source shortest path All pairs shortest
    path
Write a Comment
User Comments (0)
About PowerShow.com