Skip to content

Conversation

dkorduban
Copy link

The current implementation of shortest_path (Dijkstra's algorithm) runs in O(E^2) in worst case because q may contain O(E) elements (we add an element for each edge), and bisect.insort runs in O(E) in worst case (when the element to insert is not in the end). This pull request fixes the problem, because both heapq.heappop and heapq.heappush work in O(log(len(q))) = O(log E) = O(log V).

@coveralls
Copy link

coveralls commented Apr 6, 2018

Pull Request Test Coverage Report for Build 24

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+3.7%) to 97.619%

Totals Coverage Status
Change from base Build 23: 3.7%
Covered Lines: 533
Relevant Lines: 546

💛 - Coveralls

@dkorduban dkorduban changed the title Make shortest_path work in O(E log V) Make shortest_path run in O(E log V) Apr 10, 2018
@dkorduban dkorduban changed the title Make shortest_path run in O(E log V) Make shortest_path run in O(E log V) instead of O(E^2) Apr 10, 2018
@agroszer
Copy link
Member

agroszer commented May 1, 2018

also looks good, just coverage... or is that breakdown coming from master?

anyway, please also update the changelog

@agroszer agroszer merged commit 36753c0 into Shoobx:master May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants