第讲贪心算法分析.pptVIP

  • 11
  • 0
  • 约1.18万字
  • 约 56页
  • 2016-06-16 发布于湖北
  • 举报
Algorithm 8.2 SHORTESTPATH Input: A weighted directed graph G=(V,E), where V={1,2,..,n}. Output: The distance from vertex 1 to every other vertex in G. Assume that we have an empty heap H at the beginning. 1.Y?V-{1}; λ[1]?0; key(1)? λ[1] 2.for y?2 to n 3. if y is adjacent to 1 then 4. λ[y]=length[1,y] 5. key(y)? λ[y] 6. INSERT(H,y) 7. else 8. λ[y]? ∞ 9. key[y]? λ[y] 10. end if 11. end for NEXT PAGE Algorithm 8.2 SHORTESTPATH 12. for j?1 to n-1 13. y?DELETEMIN(H) 14. Y?Y-{y} 1

文档评论(0)

1亿VIP精品文档

相关文档