Idea for improving heapsort

84 Views Asked by At

I am trying to propose an enhanced heapsort that would combine the min and max. I got the concept of this from the Double Selection Sort which works by finding the min and max values in the array and placing the max into the last index and the min in the starting index. How do i apply this to the heapsort? For visualization, this is what i want to happen: Original Array Form:

[9, 1, 15, 2, 10]
9
/ \
1 15
/ \
2 10

Heapsort with min-max combination:

15
/ \
1 9
/ \
2 10

15
/ \
2 9
/ \
1 10

in this part, the second to the last element within the binary tree assumes the role of the minimum, while the maximum value is preserved. Specifically, in our example, the second-to-last value of the binary tree is 1, representing the minimum, while the max heapify is performed for the value 15.

10
/ \
2 9
/ \
1 15

here, the 1 will be place in the starting index and the 15 will be place in the last index.

[1, ,15]

10
/ \
2 9

9
/ \
2 10

here, the max heapify is performed, and min is stay put since the 2 is the lowest value and is already placed in the second to the last index. and then, they will be deleted from the tree and be sorted in the array.
[1, 2, 10, 15]

9 since, 9 is the only one left, it will be then deleted and inserted in the array.
[1, 2, 9, 10, 15] SORTED

  1. Is this applicable?
  2. What ways or steps do I need to implement this?

I tried coding this but its not working.

0

There are 0 best solutions below