Explain algorithm for iterative lexicographic order