1001Ferramentas
🌲 Generators

Binary Heap Builder

Build a binary heap (min or max) by inserting a sequence of numbers one by one with the sift-up operation. Shows the final heap array and its level-by-level structure. The heap is the basis of the priority queue and of heapsort.

Resultado

Heap binário

Um heap binário é uma árvore binária quase completa guardada num array, em que todo pai é menor (min-heap) ou maior (max-heap) que seus filhos. Ao inserir, o novo elemento sobe trocando de lugar com o pai até a propriedade do heap ser restaurada (sift-up). É a estrutura por trás da fila de prioridade e do algoritmo de ordenação heapsort, ambos O(n log n). Os índices: o filho de i está em 2i+1 e 2i+2.

Related Tools