Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Nice idea +1 (shortest code), but there is small bug - change a.y<a.y to b.y-a.y. Time complexity comparison here: stackoverflow.com/a/53654364/860099 Commented Dec 7, 2018 at 11:16
  • 3
    Finding the max is O(n). This is O(nlogn). Writing simple code is good as long as efficiency is not sacrificed. Commented Feb 14, 2020 at 16:52
  • @Wildhammer - actually Micro-optimisation is worth it when you have evidence that you're optimising a bottleneck.. In most cases, the simple code is better choice than high-efficient code. Commented Apr 1, 2020 at 16:47
  • @KamilKiełczewski Both array comparisons in that article have the same time complexity the difference is in their coefficient. For instance, one takes n time units to find the solution while the other one is 7n. In time complexity theory, both of these are O(n). What we are talking about in the problem of finding max is the comparison of O(n) with O(n logn). Now if you can guarantee n doesn't exceed 10 then you can use your solution otherwise O(n) algorithm is always the winner and performance(user experience) is always prior to developer experience(ask industry people, they tell you that!). Commented Apr 1, 2020 at 19:32
  • @Wildhammer nope - even if your array have n=10000 elements user will not see difference - proof HERE. Performance optimisation is good only for app bottleneck (eg. you need to process large arrays) - but in most case a performance-focus is wrong approach and time(=money) wasting. This is well known code approach mistake - read more: "micro-optimisation" Commented Apr 1, 2020 at 20:25