3 ms·
Good point :) Perhaps add a check to see if min-max is greater than K*N, and if so then use alternative method (e.g. merge sort)
by warent 9y ago
Good point :)
Perhaps add a check to see if min-max is greater than K*N, and if so then use alternative method (e.g. merge sort)
- myegorov 9y agoWhat about continuous data (real numbers, strings)? Your approach has rather limited application. On a different note, merge/sort approach (O(n log n)) is in general less efficient than the heap approach (O(n log a)), and may be impractical or wasteful of space (O(n) vs O(a)) if dealing with realtime data for example.