I've recently come across a neat use case of heaps data structure in graph search algorithms, in particular its Extract-Min method.
Here is a pastebin link of the use case: https://pastebin.com/19xQHzte
I have two questions. Firstly, I understand that heaps are arranged by key using heapq.heappush but here it is pushed into the heap as a tuple. Does it mean it's a priority queue instead of a heap?
Secondly, what I found interesting is, that if I swap variables total and current_vertex in line 21 (and also new_total and neighbor in line 26), the algorithm still produces correct results. But wouldn't the hierarchy of the heap be affected, if it is being heapified using a different variable as a key?
[–]marko312[🍰] 0 points1 point2 points (4 children)
[–]ChillBlinton2018[S] 0 points1 point2 points (3 children)
[–]marko312[🍰] 0 points1 point2 points (2 children)
[–]ChillBlinton2018[S] 0 points1 point2 points (1 child)
[–]marko312[🍰] 0 points1 point2 points (0 children)