CSC 2300 Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

CSC 2300 Data Structures

Description:

Thus, there may be more than one representative for each vertex. ... Can you come up with an example that has multiple nodes but needs just one step? ... – PowerPoint PPT presentation

Number of Views:106
Avg rating:3.0/5.0
Slides: 20
Provided by: stude6
Learn more at: http://www.cs.rpi.edu
Category:
Tags: csc | data | onestep | structures

less

Transcript and Presenter's Notes

Title: CSC 2300 Data Structures


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

2
Today
  • Dijkstras Algorithm
  • Negative Edge Costs
  • Acyclic Graphs
  • Critical Path

3
Recall Dijkstras Algorithm
  • After v6 is declared known and algorithm
    terminates

4
Stages of Dijkstras Algorithm
5
Pseudocode of Dijkstras Algorithm
  • Running time?

6
Running Time
  • Running time depends on how vertices are handled.
  • If we sequentially scan the vertices to find the
    minimum dv, each phase will take O(V) time to
    find the minimum. The time to find the minima is
    then O(V2).
  • The time to update dw is constant per update, and
    there is at most one update per edge for a total
    of O(E).
  • Total running time is O(E V2) O(V2).
  • If the graph is dense, with E T(V2), the
    algorithm is optimal.
  • What if the graph were sparse, with E T(V)?

7
Sparse Graph
  • Recall If we sequentially scan the vertices to
    find the minimum dv, each phase will take O(V)
    time to find the minimum. The time to find the
    minima is then O(V2).
  • How can we do better?
  • Keep the distances in a priority queue.
  • Select vertex v deleteMin.
  • Update ws distance decreaseKey.
  • Why is it difficult to update the distances?
  • The find operation in priority queues.
  • Is there an alternate method?
  • Insert w and the new value dw into the priority
    queue every time ws distance changes. Thus,
    there may be more than one representative for
    each vertex.
  • How to make sure that alternate method will work
    correctly?

8
Correctness
  • Does Dijkstras algorithm always give the correct
    solution?
  • Yes, as long as no edge has a negative cost.

9
Animation and Proof
  • See this site for animation and proof
    http//www.cs.auckland.ac.nz/software/AlgAnim/dijk
    stra.html
  • Proof is by contradiction.
  • Let us explain how it works.

10
Variants
  • Dijkstras algorithm solves which shortest path
    problem?
  • One source to all other nodes.
  • What are some possible variants?
  • Homework problem one destination from all other
    nodes.
  • Another variant from one given node to another.
  • Can you come up with an example that has multiple
    nodes but needs just one step?
  • Can you come up with an example that requires us
    to go through all the other nodes?

11
Negative Edge Costs
  • If a graph has negative edge costs, does
    Dijkstras algorithm work?
  • If not, can you show with an example?
  • Proposed scheme add a constant ? to each edge
    cost, to remove all negative edges.
  • Does this procedure work?
  • If not, can you show with an example?

12
Negative Edge Costs
  • What must we do to develop an algorithm that
    works?
  • Allow our algorithm to change its mind.
  • Forget about the concept of known vertices.
  • Start by placing s on a queue.
  • At each stage, dequeue a vertex v.
  • Find all vertices w adjacent to v such that dw gt
    dv cvw.
  • Update dw and pw, and place w on the queue if it
    is not already there.
  • Do you remember pw?
  • What is the running time?
  • O(E.V).

13
Pseudocode
14
Acyclic Graph
  • If the graph is acyclic, we can improve
    Dijkstras algorithm by changing the order in
    which the vertices are declared known.
  • How?
  • Select vertices in topological order.
  • The algorithm can be performed in one pass, since
    the selections and updates can take place at the
    same time as the topological sort.
  • The selection works because when a vertex is
    selected, its distance can no longer be lowered.
    Why not?
  • There is no need for a priority queue. Why not?
    Consider example.
  • The running time is O(EV).

15
Critical Path Analysis
  • Each node represents an activity that must be
    performed, along with the time it takes to
    complete the activity.
  • Called an activity-node graph.
  • Possible application construction projects.
  • Some important questions
  • What is the earliest completion time for the
    project?
  • Which activities can be delayed, and for how
    long, without affecting the minimum completion
    time?

16
Activity-node and Event-node Graphs
  • What is the role of the dummy nodes?

17
Earliest Completion Times
  • How to calculate the earliest completion time of
    the project?
  • Find the length of the longest path from the
    first event to the last event.
  • What if there are positive-cost cycles?
  • Rules EC1 0, ECw max (ECv cvw ).
  • Can you suggest an algorithm?
  • Graph is acyclic. Can you suggest an improvement?
  • Topological ordering of the nodes.

18
Latest Completion Times
  • These are earliest completion times
  • Now, we want the latest times that each event can
    finish without affecting the final completion
    time.
  • How to calculate the latest completion time of
    the events?
  • EC Rules EC1 0, ECw max (ECv cvw ).
  • What should be the rules for latest completion
    times?
  • LC Rules LCn ECn, LCv max (LCw cvw ).
  • In which order should we compute latest
    completion times?

19
Slack Times
  • Slack time for each node is the amount of time
    that completion at a node can be delayed without
    delaying the overall completion.
  • Formula Slackvw LCw ECv cvw.
  • Some activities have zero slack. These are
    crtitical activities, which must finish on time.
  • There is at least one path consisting entirely of
    zero-slack edges. Such a path is a critical path.
Write a Comment
User Comments (0)
About PowerShow.com