O(1)-time unsorting by prefix-reversals in a boustrophedon linked list

  • Authors:
  • Aaron Williams

  • Affiliations:
  • Dept. of Computer Science, University of Victoria, Canada

  • Venue:
  • FUN'10 Proceedings of the 5th international conference on Fun with algorithms
  • Year:
  • 2010

Quantified Score

Hi-index 0.00

Visualization

Abstract

Conventional wisdom suggests that O(k)-time is required to reverse a substring of length k. To reduce this time complexity, a simple and unorthodox data structure is introduced. A boustrophedon linked list is a doubly-linked list, except that each node does not differentiate between its backward and forward pointers. This lack of information allows substrings of any length to be reversed in O(1)-time. This advantage is used to efficiently unsort permutations using prefix-reversals. More specifically, this paper presents two algorithms that visit each successive permutations of 〈n〉 = {1, 2,..., n} in worst-case O(1)-time (i.e. loopless). The first visits the permutations using a prefix-reversal Gray code due to Zaks [22], while the second visits the permutations in co-lexicographic order. As an added challenge, both algorithms are nonprobing since they rearrange the data structure without querying its values. To accomplish this feat, the algorithms are based on two integer sequences: A055881 in the OEIS [17] and an unnamed sequence.