Skip to content

Files

Latest commit

2e108b8 · Jul 20, 2023

History

History
This branch is 2 commits ahead of, 16 commits behind igorwojda/kotlin-coding-challenges:main.

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 20, 2023
Feb 7, 2023
Feb 7, 2023

Max binary heap

Instructions

Implement Max binary heap. In the Max Binary Heap each node may have from 0 to 2 children. Parent nodes are always larger than child nodes, in other words all children are always smaller than a parents. Heap always have to be filled from "left side" meaning that we can add children to new level only if current level is full (each parent from previous level have two children).

Challenge | Solution

Examples

// ----------Heap------------
//
//           9
//         /   \
//        7     6
//       / \   /
//      3   2 4
//
// --------------------------

val heap = MaxBinaryHeap<Int>()
heap.add(9)
heap.add(7)
heap.add(6)
heap.add(3)
heap.add(2)
heap.add(4)