Fun-sort--or the chaos of unordered binary search

  • Authors:
  • Therese Biedl;Timothy Chan;Erik D. Demaine;Rudolf Fleischer;Mordecai Golin;James A. King;J. Ian Munro

  • Affiliations:
  • Department of Computer Science, University of Waterloo, Waterloo, ON, Canada N2L 3G1;Department of Computer Science, University of Waterloo, Waterloo, ON, Canada N2L 3G1;MIT Laboratory for Computer Science, Cambridge, MA;Department of Computer Science, The Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong;Department of Computer Science, The Hong Kong University of Science and Technology, Clear Water Bay, Kowloon, Hong Kong;Department of Computer Science, University of Waterloo, Waterloo, ON, Canada N2L 3G1;Department of Computer Science, University of Waterloo, Waterloo, ON, Canada N2L 3G1

  • Venue:
  • Discrete Applied Mathematics - Fun with algorithms 2 (FUN 2001)
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Usually, binary search only makes sense in sorted arrays. We show that insertion sort based on repeated "binary searches" in an initially unsorted array also sorts n elements in time Θ(n2 log n). If n is a power of two, then the expected termination point of a binary search in a random permutation of n elements is exactly the cell where the element should be if the array was sorted. We further show that we can sort in expected time Θ(n2 log n) by always picking two random cells and swapping their contents if they are not ordered correctly.