Insertion-sort based approach is much faster for sorting head/tail indexes.

TBD: check if it's better to do one extension of the length of the
index arrays and then do in-place insertion sort.
Graph method to check if an edge (head, tail) exists.
Graph edgeID method to find the index of edge (head, tail).