Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But heap gives you O(1) max/min and Binary tree gives you O(log(n)) of max/min. Am I wrong?


In C++ (for example) getting the minimum and maximum is an O(1) operation [1][2]. I guess this is probably enabled through some extra bookkeeping and many other languages may do the same.

[1]: https://en.cppreference.com/w/cpp/container/set/begin

[2]: https://en.cppreference.com/w/cpp/container/set/rbegin




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: