Back to course home
0% completed
Vote For New Content
For the python solution, is there a benefit of the code block of "while minHeap:...
Richard Yuan
Aug 12, 2022
For the python solution, is there a benefit of the code block of "while minHeap: topNumbers.append(heappop(minHeap)[1])"? Would it not be cheaper time wise to simply iterate through the tuples within minHeap and append the element to topNumbers? This way will result in only O(k) rather than O(klogk) time, which won't matter in the overall time complexity. However, I am just trying to see if there is some advantage to the first approach that I am missing.
0
0
Comments
Comments
R
Richard Yuan3 years ago
Nvm it could be used to free up the space taken by the min heap.
On this page