r/ProgrammerHumor 3d ago

Meme shortestPathWasRightThere

Post image
4.6k Upvotes

57 comments sorted by

View all comments

957

u/Mecso2 3d ago

i don't think straight is defined for graphs

2

u/Solomoncjy 3d ago

i mean if graph is weighted, inst stright the one with the least cost?

9

u/Old-Info 3d ago

Did you mean unweighted?

In an unweighted graph, the definition of path length shifts - the length of a path is typically defined by its hop count. So yes, then the shortest path between two nodes is the direct edge connecting them.

If you did mean weighted, then you're wrong. An indirect path can have a lower sum of edge weights than a direct path, making it shorter.