Project 3 Part II Dijkstras shortest path DSP - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Project 3 Part II Dijkstras shortest path DSP

Description:

heap functions. remove() remove the root, that is, the node with minimum key. ... Question: how to find a vertex's location in a heap? ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 5
Provided by: csUi
Category:

less

Transcript and Presenter's Notes

Title: Project 3 Part II Dijkstras shortest path DSP


1
Project 3Part II Dijkstras shortest path (DSP)
Use a min-heap to implement DSP
V set of all vertices S set of completed
vertices. vertices in H V -S - Root of the
heap has the smallest distance from the source s
2
Implementation issues
  • heap class
  • It is a min-heap.
  • Refer to Lafores max-heap implementation.
  • First, define a new Node class
  • E.g.
  • Class Node
  • int vertex_id
  • double distance
  • .
  • heap functions
  • remove() remove the root, that is, the node
    with minimum key.
  • trickeDown(int heap_id) It can be used by remove
    function.
  • insert( int vertex_id, double dist) insert a
    new node into the heap
  • trickleUp( int heap_id) It can be used by insert
    function.
  • decreaseDistance( int vertex_id, double dist)
    change a nodes key value.
  • Note

3
Use a map to store vertices locations in the heap
  • class heap
  • private Node heapArray
  • private int currentSize
  • private int map
  • .
  • mapi
  • mapi changes as the node for vertex i is moving
    in the heap.

4
Incorporate DSP into myGraph class
  • public void DSP(string s)
  • String shortestPath( String s, String t,
    boolean byHops)
  • If byHops true, use breath first traversal
  • If byHops false, call DSP.
  • Just modeify old shortestpath method.
  • int SPTree
  • Like BFTree and DFTree, store the shortest paths
    generated by DSP.
  • SPTreei the predecessor of vertex i on the
    shortest path from s to i.
Write a Comment
User Comments (0)
About PowerShow.com