An intuitive understanding of heapsort?

后端 未结 7 2200
春和景丽
春和景丽 2021-01-30 00:18

At school we are currently learning sorting algorithms in Java and I got for my homework the Heap Sort. I did my reading, I tried to find out as much as I could, but it seems I

7条回答
  •  灰色年华
    2021-01-30 00:54

    Suppose you have a special data structure (called a heap) which allows you to store a list of numbers and lets you retrieve and remove the smallest one in O(lg n) time.

    Do you see how this leads to a very simple sorting algorithm?

    The hard part (it's actually not that hard) is implementing the heap.

提交回复
热议问题