# Dijkstra's Algo

It is the greedy Algo to find the min/max-cost path of a graph.

![](https://2628390332-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0RnkuvOeqe0clAIN1b%2F-MgLuliQ7QiDqt5K6mfz%2F-MgLw3oRJIvYY6POYeTD%2FDijkstra_Animation.gif?alt=media\&token=4a772dc0-679c-409a-a384-dfc372cdebea)

The implementation is using

* BFS
* PriorityQueue: BFS use a queue to keep the node needing to iterate, Dikstra's Algo uses a priority queue to keep the next node is the min/max cost instead.
* Use an array to keep the min/max value in each node

Time complexity:

O(E\*logV), where E is the total edges count, V is the vertex count

* We don't revisit the same node, which means we don't reuse the same edge.
* For each edge, we pop out the best node (according to our principle) from a min(max)Heap.
  * it takes log V, &#x20;
* Total computation is  E \* log V&#x20;
