CSC 2300 Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

CSC 2300 Data Structures

Description:

Single-Source Shortest Path ... Illustration. Say initial vertex is v3: After finding all vertices whose path length from s is 1: ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 21
Provided by: stude6
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: CSC 2300 Data Structures


1
CSC 2300Data Structures Algorithms
  • April 3, 2007
  • Chapter 9. Graph Algorithms

2
Today
  • Shortest-Path Algorithms
  • Unweighted Shortest Paths
  • Dijkstras Algorithm

3
Single-Source Shortest Path
  • Problem Given as input a weighted graph G
    (V,E) and a distinguished vertex s, find the
    shortest weighted path from s to every other
    vertex in G.
  • Example

4
Edges of Negative Costs
  • Edges of negative costs can cause problem.
  • Example
  • Consider a path from v5 to v4.
  • What happens to shortest paths when a
    negative-cost cycle is present in a graph?
  • In the absence of negative-cost cycles, the
    shortest path from s to s is zero.

5
Unweighted Shortest Paths
  • We may say that all edges have weight 1.

6
Illustration
  • Say initial vertex is v3
  • After finding all vertices whose path length from
    s is 1

7
Illustration
  • After finding all vertices whose path length from
    s is 2
  • Final shortest paths

8
Breadth-first Search
  • This strategy for searching a graph is known as
    breadth-first search.
  • It operates by processing the vertices in layers
    the vertices closest to the start are evaluated
    first, and the most distant vertices are
    evaluated last.
  • What is the equivalent traversal scheme for trees?

9
Initial Configuration of Table
10
Pseudocode
  • Running time of this algorithm?

11
Inefficiency
  • Here is an example
  • How to remove this efficiency?
  • Use a queue.

12
Improved Pseudocode
13
Example
14
Weighted Shortest Paths
  • Dijkstras algorithm
  • Greedy algorithm solves a problem in stages by
    doing what appears to be the best choice at each
    stage.

15
Dijkstras Algorithm
  • Initial configuration After v1 is declared
    known

16
Dijkstras Algorithm
  • After v4 is declared known After v2 is declared
    known

17
Dijkstras Algorithm
  • After v5 and v3 are known After v7 is declared
    known

18
Dijkstras Algorithm
  • After v6 is declared known and algorithm
    terminates

19
Stages of Dijkstras Algorithm
20
Pseudocode of Dijkstras Algorithm
  • Running time?
Write a Comment
User Comments (0)
About PowerShow.com