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...
Answer the following questions true (T) or false (F)
1. A recursively written method will usually run slower and use more storage than an equivalent iterative version. 2. A recursive method must never return a value.
Column widths can be adjusted by dragging the column border to widen or narrow the column
Indicate whether the statement is true or false
List and describe the steps to configure a DHCP server.
What will be an ideal response?
The compositionReady event fires when an animation is ready to play.
Answer the following statement true (T) or false (F)