The time complexity of getting first top k elements from heap is klog(n), because each time you remove the first element, the heap heapify to maintain its heap property. Building Heap is O(n) op, but heapify is O(log(n)) .There is no such concept to take first K element form Map (in C++ is unordered map I think)it is O(1) only when you want to peek the first heap element without taking it out