1-Aryan sort heap?

A back, we were given the task of writing a program c that sorts an array of n numbers using d-ary max-heap (a bunch where each node has up to d children). The program should ask the user to enter the value d, a value between 2 and the size of the array. While I was testing my program, I accidentally entered 1 as the value of d, and somehow the algorithm successfully sorted the array correctly using the 1-arch heap, although it took a lot more time than the normal values ​​of d.

How is this possible? A 1-heap heap is not even a heap, it is just like a list, each node has only one child. Can someone explain how this sorting can happen?

+5
source share
1 answer

The 1-hedge heap is still a heap and satisfies all the invariants required by sorting the heap:

  • The first element is the largest element.
  • Percolation can move the top element to the correct position.

In practice, a 1-heap heap is a tree where each node has one child - this is also known as a separate list. In addition, the heap constraint means that the child of the node is smaller than the parent of the node. So, just put, a 1-heap heap is a separate list, sorted in reverse order.

( ). , , .

+7

All Articles