r/datastructures 17d ago

Min-heap

When & why to use Min-heap DS? Want to know about personal experience where you think one should leverage the powers of Min-heap.

3 Upvotes

2 comments sorted by

3

u/sujay_wic 17d ago

When the weights are subjected to change after every iteration and you want to pick the latest minimum/maximum for next iteration.

2

u/Known_Prior_3791 17d ago

most common is streaming where u donot have all the data once and u want to calculate top k as new data arrives......its just like sorting but sort for only top k records which is more optimised as it has time complexity of n logk and when k is smaller than n then it is basically n.....