Is this the best way to put the array into descending order?
An array is sorted into ascending order. The following sequence of steps will put the array into descending order:
1) Copy the array into a maxheap
2) Remove the elements from the maxheap and put them in order into the array.
No. The sequence of steps describes a heap sort, which is O (n log n). A more efficient way to reverse the
order of the sort of the array would be to exchange/swap the first and last elements, the second and one less than the last, etc.
Each exchange takes constant time, and there are exchanges performed for an array of size n, so this operation would be O(n).
For a large array, this could be substantially faster than using a heap sort.
You might also like to view...
When an underlying table designates a field as a lookup field, Access inserts a(n) ________ for this field
Fill in the blank(s) with correct word
Which of the following file properties is generated by Windows Vista and can NOT be changed by the user?
A) Date modified B) Keyword C) Title D) Author