Introduction
In general, by Heap, we used to consider Binary Heap, i.e., which is a complete binary tree and it is either
max-heap(value of parent node is greater than or equal to the value of all child nodes, this property recursively valid for all nodes)
or
min-heap(value of parent node is greater than or equal to the value of all child nodes, this property recursively valid for all nodes).
K-ary Heap is a generalized version of Binary Heap. Instead of two, for the K-ary heap, there are at most k child nodes of a parent node. But other properties remain the same, i.e.,
- it is a complete tree
- all nodes in the tree follow a specific order, either max-heap or min-heap

Max ternary heap (K=3)

Min ternary heap (K=3)
Implementation
As K-ary Heap is a complete tree, it can be represented sequentially in an array where
- array[1] is the root of the heap
- child nodes of the parent node at index i( i.e, array[i] ) are at
(k*i)+1,(k*i)+2,….....,(k*i)+k
- The parent node of the node at ith index is at (i-1)/k index.
The above max-heap can be represented as

Observe that the nodes of the heap on the same level appear one after the other in the array




