I'm a high schooler who has been self-learning graph algorithms for a month or two now.
I was wondering why the distance array in Dijkstra's algorithm is initialized to infinity (INT_MAX in C++) when it could just be set to a negative number? Since Dijkstra's isn't even used for negative numbers, why isn't the distance array set to some arbitrary negative number (say, -1) and instead a very large number which takes up far more space? It's possible that I'm overestimating the space occupied in memory by a very large INT value.
I'd appreciate any constructive feedback.
int
s take up the same amount of space regardless of their value. $\endgroup$INT_MAX >> 1
to represent infinity. Certainly you want to do this if using an adjacency matrix instead of adjacency lists, because it means that you save a special case by not needing to worry about overflow. $\endgroup$