Class HeapSortInt


  • public class HeapSortInt
    extends java.lang.Object
    An implementation of the heap sort algorithm as described in Cormen et al. Introduction to Algorithms. This class sorts two arrays, with respect to the values of the elements in the first array. There is also an option to sort only N entries with the highest values. In this case, there are two options:
    • The top N entries can be sorted in ascending order, so that the N elements with the highest values are placed in the array's last N positions (the highest entry of the arrays will be in array[array.length-1], the second highest in array[array.length-2] and so on.
    • The top N entries can be sorted in descending order, so that the N elements with the highest values are placed in the array's first N positions (the highest entry of the array will be in array[0], the second highest entry will be in array[1] and so on.
    Author:
    Vassilis Plachouras
    • Constructor Summary

      Constructors 
      Constructor Description
      HeapSortInt()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void ascendingHeapSort​(int[][] A)
      ascendingHeapSort
      static void ascendingHeapSort​(int[] A, int[] B)
      Sorts the given arrays in ascending order, using heap-sort.
      static void ascendingHeapSort​(int[] A, int[] B, int[] C)
      Sorts the given arrays in ascending order, using heap-sort.
      static void ascendingHeapSort​(int[] A, int[] B, int[] C, int topElements)
      Sorts the top topElements of the given array in ascending order, using heap sort.
      static void ascendingHeapSort​(int[] A, int[] B, int[] C, int[] D)
      ascendingHeapSort
      static void descendingHeapSort​(int[] A, int[] B)
      Sorts the given arrays in descending order, using heap-sort.
      static void descendingHeapSort​(int[] A, int[] B, int[] C)
      Sorts the given arrays in descending order, using heap-sort.
      static void descendingHeapSort​(int[] A, int[] B, int[] C, int topElements)
      Sorts the top topElements of the given array in descending order, using heap sort for sorting the values in ascending order and then reversing the order of a specified number of elements.
      static void descendingHeapSort​(int[] A, int[] B, int[] C, int[] D)
      Sorts the given arrays in descending order, using heap-sort by the first array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HeapSortInt

        public HeapSortInt()
    • Method Detail

      • ascendingHeapSort

        public static void ascendingHeapSort​(int[] A,
                                             int[] B,
                                             int[] C)
        Sorts the given arrays in ascending order, using heap-sort.
        Parameters:
        A - int[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
        C - int[] an additional array to sort by A.
      • ascendingHeapSort

        public static void ascendingHeapSort​(int[] A,
                                             int[] B,
                                             int[] C,
                                             int[] D)
        ascendingHeapSort
        Parameters:
        A - int[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
        C - int[] an additional array to sort by A.
        D - int[] an additional array to sort by A.
      • ascendingHeapSort

        public static void ascendingHeapSort​(int[] A,
                                             int[] B)
        Sorts the given arrays in ascending order, using heap-sort.
        Parameters:
        A - int[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
      • descendingHeapSort

        public static void descendingHeapSort​(int[] A,
                                              int[] B)
        Sorts the given arrays in descending order, using heap-sort.
        Parameters:
        A - int[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
      • ascendingHeapSort

        public static void ascendingHeapSort​(int[][] A)
        ascendingHeapSort
        Parameters:
        A - an arry to sort ascending
      • descendingHeapSort

        public static void descendingHeapSort​(int[] A,
                                              int[] B,
                                              int[] C)
        Sorts the given arrays in descending order, using heap-sort.
        Parameters:
        A - double[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the
        C - int[] an additional array to sort by A. values of the first array.
      • descendingHeapSort

        public static void descendingHeapSort​(int[] A,
                                              int[] B,
                                              int[] C,
                                              int[] D)
        Sorts the given arrays in descending order, using heap-sort by the first array.
      • ascendingHeapSort

        public static void ascendingHeapSort​(int[] A,
                                             int[] B,
                                             int[] C,
                                             int topElements)
        Sorts the top topElements of the given array in ascending order, using heap sort.
        Parameters:
        A - double[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
        C - int[] an additional array to sort by A.
        topElements - int the number of elements to be sorted.
      • descendingHeapSort

        public static void descendingHeapSort​(int[] A,
                                              int[] B,
                                              int[] C,
                                              int topElements)
        Sorts the top topElements of the given array in descending order, using heap sort for sorting the values in ascending order and then reversing the order of a specified number of elements.
        Parameters:
        A - double[] the first array to be sorted.
        B - int[] the second array to be sorted, according to the values of the first array.
        topElements - int the number of elements to be sorted.