16 ms·
But heap gives you O(1) max/min and Binary tree gives you O(log(n)) of max/min. Am I wrong?
by mrkentutbabi 5y ago
But heap gives you O(1) max/min and Binary tree gives you O(log(n)) of max/min. Am I wrong?
- meribold 5y agoIn 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 https://en.cppreference.com/w/cpp/container/set/begin [2]: https://en.cppreference.com/w/cpp/container/set/rbegin https://en.cppreference.com/w/cpp/container/set/rbegin