# Why are shortest paths sorted?

**URL:** https://igraph.discourse.group/t/why-are-shortest-paths-sorted/626
**Category:** Development
**Tags:** C
**Created:** [13 February 2021 19:47 UTC](https://igraph.discourse.group/t/why-are-shortest-paths-sorted/626 "2021-02-13T19:47:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [13 February 2021 19:47 UTC](https://igraph.discourse.group/t/why-are-shortest-paths-sorted/626/1 "2021-02-13T19:47:03Z")

</div>

@Gabor Do you recall why the shortest paths obtained with Dijkstra are sorted? See here:

> <https://github.com/igraph/igraph/blob/develop/src/paths/dijkstra.c#L1051>

The unweighted version does not sort.

A Bellman-Ford version of the function was just added. Is there any reason to add the sorting to this new function?

---

<div class="post-metadata">

### Author: ![Gabor](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gabor/32/15_2.png) [@Gabor](https://igraph.discourse.group/u/Gabor)
#### Post date: [13 February 2021 20:12 UTC](https://igraph.discourse.group/t/why-are-shortest-paths-sorted/626/2 "2021-02-13T20:12:29Z")

</div>

I guess: [rigraph/structural.properties.R at a14fc50abf9bf3ae17b870ccbc21f88d0eefed6e · igraph/rigraph · GitHub](https://github.com/igraph/rigraph/blob/a14fc50abf9bf3ae17b870ccbc21f88d0eefed6e/R/structural.properties.R#L355)

If the unweighted version does not, then it should, I guess, unless it is shorted in R.
