#timestamp 2025-03-25

heaps: k-smallest elements

asymptotic running time

add() -> for n elements (n>k):

Θ(klog(k)insertion+(nk)log(k)deletion)=Θ(nlogk)

get() -> for n elements (n>k):

O(k1+klog(k)+klog(k))=O(k+2klog(k))=O(klog(k))

-> overall time

O(nlogk)

asymptotic memory consumption

-> total memory consumption:

Θ(k)
  1. https://en.cppreference.com/w/cpp/algorithm/sort ↩︎