冒泡排序也不是健壮的

  • After publishing an article on bubble sort, the author came across another account claiming bubble sort is more robust than better algorithms.
  • The example showed that in a scenario with unreliable comparisons, bubble sort's inefficient repeated comparisons and short moves seemed to repair faults and minimize damage.
  • However, the author argues that the real reason for bubble sort's reliability is its exit condition of scanning the sequence to verify it is in order before handing back a sorted sequence.
  • By adding the same exit condition to insertion sort and running the same experiment, it was found that checked insertion sort is not only more efficient but also over ten times as robust as bubble sort.
  • A reader pointed out that game tournaments are a class of sorting algorithms designed to work with sloppy comparison functions.
  • The premise of the article was based on a false assumption that David Ackley had implemented the typical, optimized bubble sort. The author's implementation contains an optimization that exits early if the list is sorted but may run more iterations if the list is unsorted.
  • Implementations of different sorting algorithms (bubble sort, regular insertion sort, checked insertion sort) and a function to compute the distance and verify the sorted sequence are provided.
  • The distribution of errors is obtained by running the sorting algorithms with a faulty comparison function on a shuffled deck of 52 cards.
阅读 13
0 条评论