Skip to main content
ARCHOS 525 BLUEPRINT · /d/dgm_code-top-k-heaps-and-selection

Top-K, Binary Heaps, K-Way Merge & Quickselect

6 COMPONENTS · 6 FLOWS · UPDATED 2026-11-24
GITHUB README / PR PREVIEW CARD
[![Top-K, Binary Heaps, K-Way Merge & Quickselect — ArchOS Architecture](https://archos.sageideas.dev/d/dgm_code-top-k-heaps-and-selection/opengraph-image)](https://archos.sageideas.dev/d/dgm_code-top-k-heaps-and-selection)

*Interactive architecture diagram powered by [ArchOS Studio](https://archos.sageideas.dev/d/dgm_code-top-k-heaps-and-selection)*
NOTION / DOCS / CONFLUENCE EMBED
<iframe src="https://archos.sageideas.dev/embed/dgm_code-top-k-heaps-and-selection" width="100%" height="580" style="border:1px solid rgba(240,236,225,0.14);border-radius:6px;" loading="lazy" title="Top-K, Binary Heaps, K-Way Merge & Quickselect — Interactive in ArchOS"></iframe>
PORTABLE MERMAID SPEC (GITHUB / NOTION / RFC)
flowchart LR
  client_0["Unsorted / K-Streams"]
  n1_1[("Min-Heap")]
  n2a_2["Quickselect Partition"]
  n2b_3[("Two-Heap Median")]
  n3_4["Ranked Top-K Output"]
  downstream_5["Downstream & OTel"]
  client_0 -->|"1. Push/Pop · Olog K"| n1_1
  n1_1 -->|"2a. Partition · ON"| n2a_2
  n1_1 -->|"2b. Rebalance · Olog N"| n2b_3
  n2a_2 -->|"3a. Extract K · Output"| n3_4
  n2b_3 -->|"3b. Merge · RAM"| n3_4
  n3_4 -.->|"4. Emit / · OTLP/API"| downstream_5

COMPONENT STACK (6)

  • Unsorted / K-StreamsSTATELESS
    Logs, Scores or Timestamps
  • Min-HeapSTATEFUL
    Evicts smallest above K elements
  • Quickselect PartitionSTATELESS
    Hoare/3-way pivot O avg
  • Two-Heap MedianSTATEFUL
    Max-heap low + Min-heap high
  • Ranked Top-K OutputSTATELESS
    Sorted K winners or K-th order
  • Downstream & OTelSTATELESS
    Consumers, metrics & SLOs

REQUEST & DATA FLOW (6)

  1. Unsorted / K-Streams → Min-Heap (Push/Pop)[Olog K]
  2. Min-Heap → Quickselect Partition (Partition)[ON]
  3. Min-Heap → Two-Heap Median (Rebalance)[Olog N]
  4. Quickselect Partition → Ranked Top-K Output (Extract K)[Output]
  5. Two-Heap Median → Ranked Top-K Output (Merge)[RAM]
  6. Ranked Top-K Output → Downstream & OTel (Emit /)[OTLP/API]
Configure NGINX / Postgres / K8s →60-Sec L4–L7 Diagnostic →