Heaps and Priority Queues: Binary Heap, Heapify, Heap Sort and Top-K in C#
A heap is an array-backed tree that always keeps the smallest element on top; insert and remove-min are O(log n) and bottom-up build-heap is O(n). We write a BinaryHeap and heap sort in C#, show with real output that .NET's 4-ary PriorityQueue is not FIFO for equal priorities, and finish with top-K, k-way merge and running median examples plus a BenchmarkDotNet measurement.
8 Nov 2026
·
14 min
·
2