Skip to main content

Heap

An array-based priority-queue ADT and parent/child index formulas.

ν•œκ΅­μ–΄ 원문

English edition note: The two reference links were empty in the original. The index formulas below assume one-based indexing and integer division for the parent. The ADT listing is pseudocode.

#About heaps


Concept reference: no link supplied in the original.
Binary tree reference: no link supplied in the original.
Implementations: array-based heaps and linked-list-based heaps log(n): the height of a heap with n nodes

#Heap implementation


#πŸ“š Implementation

#1. Priority-queue abstract data type (ADT)

Array-based heap

create() // Create a priority queue
init(q) // Initialize the priority queue
is_empty(q) // Check whether the priority queue is empty
is_full(q) // Check whether the priority queue is full
insert(q, item) // Insert item into the priority queue
delete(q) // Remove the highest-priority item from the priority queue
find(q) // Find the highest-priority item in the priority queue
#Array heap

Left child: 2 * (parent index)
Right child: 2 * (parent index) + 1
Parent: (child index) / 2

Connect