Documentation of 'smile.sort.ShellSort' Java class
ShellSort
smile.sort

Class ShellSort



  • public class ShellSort
    extends java.lang.Object
    Shell sort is a sorting algorithm that is a generalization of insertion sort, with two observations:
    • insertion sort is efficient if the input is "almost sorted", and
    • insertion sort is typically inefficient because it moves values just one position at a time.
    Shell sort improves insertion sort by comparing elements separated by a gap of several positions. This lets an element take "bigger steps" toward its expected position. Multiple passes over the data are taken with smaller and smaller gap sizes. The last step of Shell sort is a plain insertion sort, but by then, the array of data is guaranteed to be almost sorted.

    The original implementation performs O(n2) comparisons and exchanges in the worst case. A minor change given in V. Pratt's book improved the bound to O(n log2 n). This is worse than the optimal comparison sorts, which are O(n log n).

    For n < 50, roughly, Shell sort is competitive with the more complicated Quicksort on many machines. For n > 50, Quicksort is generally faster.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void sort(double[] a)
      Sorts the specified array into ascending numerical order.
      static void sort(float[] a)
      Sorts the specified array into ascending numerical order.
      static void sort(int[] a)
      Sorts the specified array into ascending numerical order.
      static <T extends java.lang.Comparable<? super T>>
      void
      sort(T[] a)
      Sorts the specified array into ascending order.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • sort

        public static void sort(int[] a)
        Sorts the specified array into ascending numerical order.
      • sort

        public static void sort(float[] a)
        Sorts the specified array into ascending numerical order.
      • sort

        public static void sort(double[] a)
        Sorts the specified array into ascending numerical order.
      • sort

        public static <T extends java.lang.Comparable<? super T>> void sort(T[] a)
        Sorts the specified array into ascending order.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.