Home/Algo Bridge/Heap / Priority Queue/LC_215
⚡ Practice in Flashcards
🌉 Problem-Level AI BridgeLC_215 · 中等

LC_215 (Kth Largest Element) ➔ Top-K and Top-P (Nucleus) Sampling

Quickselect and min-heaps find the top-K elements without full array sorting in O(N) expected time.

1️⃣ 1️⃣ Classical DSA Origin

LC_215 · Kth Largest Element

Pattern: Heap / Priority Queue — Complete binary tree representation where the root exposes the extreme value in O(1) time. Dynamic insertions and deletions rebalance in O(log K) time, serving as the core engine for streaming Top-K logit filtering and multi-way KV stream merges.

⚡ Open LC-215 Solution ➔
2️⃣ 2️⃣ Production AI System Transfer

Mixture of Experts (MoE) Top-K Gating & Token Dispatch · Top-K and Top-P (Nucleus) Sampling

Industrial Application: Selects top-K active experts in Mixture-of-Experts (MoE) routing and performs top-K logit filtering during generation.

🧬 Target AI Kernel Interface
def sample_top_k_top_p(logits: torch.Tensor, top_k: int = 0, top_p: float = 1.0, temperature: float = 1.0) -> int

🔗 Related Algorithmic Bridges

LC_215 ➔ Monte Carlo Tree Search (MCTS) for Reasoning
Quickselect and min-heaps find the top-K elements without full array sor...
LC_215 ➔ MoE Top-K Gating Routing & Sparse Expert Dispatch
Quickselect and min-heaps find the top-K elements without full array sor...
LC_215 ➔ MoE Load Balancing Auxiliary Loss
Quickselect and min-heaps find the top-K elements without full array sor...
LC_75 ➔ MoE Top-K Gating Routing & Sparse Expert Dispatch
Dutch National Flag algorithm performs in-place three-way partitioning i...
LC_75 ➔ MoE Load Balancing Auxiliary Loss
Dutch National Flag algorithm performs in-place three-way partitioning i...
LC_75 ➔ Top-K and Top-P (Nucleus) Sampling
Dutch National Flag algorithm performs in-place three-way partitioning i...
← LC_215 (Kth Largest Element) → Mixture of Experts (MoE) Top-K Gating & Token DispatchLC_23 (Merge K Sorted Lists) → Hybrid RAG (Dense+Sparse), Interval Merge & Context Packing →