ต้นไม้เริ่มต้น

อัลกอริทึมการแทรก (Insertion Algorithm)
insert(heap, n, item) − Begin
if heap is full, then exit
else
n := n + 1
for i := n, i > 1, set i := i / 2 in each iteration, do
if item ≤ heap[i/2], then break
heap[i] = heap[i/2]
done
end if
heap[i] := item
End
ตัวอย่าง
สมมติต้องการแทรก 30 เข้า Heap:
