Title says it all. Why is the choice of data structure for Dijkstra's algorithm a priority queue, rather than a simple sorted list?
Remember to vote up questions/answers you find interesting or helpful (requires 15 reputation points)
|
0
|
|||||||||||||||||
|
closed as off topic by David Eppstein, Harry Gindi, Noah Snyder, Reid Barton, Scott Carnahan♦ Mar 10 at 2:44 |
|
3
|
Consider the running time for adding a new element to a sorted list, keeping the list sorted. If the list is an array, you can find the insertion point in |
||
|
|
You can accept an answer to one of your own questions by clicking the check mark next to it. This awards 15 reputation points to the person who answered and 2 reputation points to you.
|
1
|
|
||||||
|
|
-1
|
You have to understand a priority queue is an abstract data structure. There isn't really "a priority queue", there's implementations of the idea of a priority queue. You could very well keep a list, sort it, and then that would be your priority queue. The thing is, that will (likely) have a worse running time than other ways of implementing a priority queue. Keep in mind complexity deals with asymptotic running time. In practice, there are still constant in there and they make a difference, so we want to use a better implementation of a priority queue than constantly sorting an entire list. So don't let "priority queue" versus "sorted list" confuse you; they are conceptually one in the same. |
|||
|
