Abstract

A Heap is a specialized tree-based data structure that satisfies strict structural shape invariants and relative priority ordering properties. Bypassing the pointer overhead of traditional dynamic trees, it serves as the standard physical implementation layer for the Priority Queue ADT.

  • Category: Complete Tree Index Structure
  • Primary Backbone: Bounded flat contiguous arrays without explicit link pointers.
  • Key Advantage: Fast constant-time root access paired with predictable mutation paths.

Core Structural Constraints

A valid Binary Heap structure must simultaneously satisfy three core geometric rules:

  1. Binary Tree Property: Every individual node inside the hierarchy is restricted to a maximum of two children (maintaining 0, 1, or 2 outgoing branches).
  2. Heap Property: For any two nodes and , if functions as the structural parent of child node , then the priority value of must be higher than or equal to the priority value of .
  3. Shape Property: The structure must operate as a Complete Tree. Every horizontal level of the tree must be fully populated with nodes except for the bottom-most active level, which must be packed sequentially from left to right without internal gaps.

Heap Topological Classifications

Priority rankings are determined directly by evaluating element key weights. Because relative priorities define all branch paths, duplicate keys are permitted throughout the layout; internal priority ties are resolved arbitrarily.

Architectural DimensionMin-Heap ConfigurationMax-Heap Configuration
Structural Ordering
Root Node AssignmentMinimum global value (Highest Priority)Maximum global value (Highest Priority)
Priority Processing LogicSmaller key weights assume higher rankLarger key weights assume higher rank

Data Structure Operations

Peek()

Identifies and returns the absolute highest-priority element tracking within the collection.

  • Time Complexity: strictly constant time.
  • Algorithmic Logic: The Heap Property guarantees that the highest-priority element always resides at the root position.

Push(element) (Element Insertion)

Appends a new value to the structure while maintaining the Shape Property and the Heap Property.

  • Time Complexity: worst-case boundary path.

Algorithm 39 Heap Element Insertion (Bubble Up)

procedure Push(element,heap,nelement, heap, n)

heap[n]element\text{heap}[n] \gets element

currncurr \gets n

nn+1n \gets n + 1

while curr>0curr > 0 do

parentcurr12parent \gets \lfloor \frac{curr - 1}{2} \rfloor

if HasHigherPriority(heap[curr],heap[parent]\text{heap}[curr], \text{heap}[parent]) then

Swap(heap[curr],heap[parent]\text{heap}[curr], \text{heap}[parent])

currparentcurr \gets parent

else

break

Pop() (Highest-Priority Extraction)

Removes the highest-priority element from the container while preserving heap properties.

  • Time Complexity: worst-case boundary path.

Algorithm 40 Heap Root Extraction (Trickle Down)

procedure Pop(heap,nheap, n)

if n==0n == 0 then

return

heap[0]heap[n1]\text{heap}[0] \gets \text{heap}[n - 1]

nn1n \gets n - 1

curr0curr \gets 0

while 2curr+1<n2 \cdot curr + 1 < n do

left2curr+1left \gets 2 \cdot curr + 1

right2curr+2right \gets 2 \cdot curr + 2

targetlefttarget \gets left

if right<nright < n and HasHigherPriority(heap[right],heap[left]\text{heap}[right], \text{heap}[left]) then

targetrighttarget \gets right

if HasHigherPriority(heap[target],heap[curr]\text{heap}[target], \text{heap}[curr]) then

Swap(heap[curr],heap[target]\text{heap}[curr], \text{heap}[target])

currtargetcurr \gets target

else

break

Child Swap Selection Logic

When trickling an element down, the engine must swap with the highest-priority child branch. Swapping with the weaker child would violate the Heap Property by leaving a child node with higher priority than its newly assigned parent.


Flat Array Implementation Mapping

Because heaps satisfy the strict structural definition of a complete tree, they map directly into sequential hardware memory arrays without requiring pointers or leaving empty slots between items.

For an entry element located at array coordinate position under standard 0-based indexing, coordinate translations map to the following mathematical formulas:

  • Parent Offset Location:
  • Left Child Offset Location:
  • Right Child Offset Location:
  • Next Available Shape Slot: Coordinates directly to array index (where represents the total active element count).

Architectural Complexity Summary

  • Peek() Operational Latency: constant time execution.
  • Push() Insertion Latency: bounding log steps.
  • Pop() Extraction Latency: bounding log steps.
  • Total Structural Space Footprint: Exactly flat contiguous allocations.

Related Notes