Andrea Koutifaris
1 min readNov 13, 2019

--

Sorting time complexity is, in the best case scenario, O(n*log(n)), whereas searching an element in a unordered set is O(n).

This means that the bigger the input is, and the more the sorting algorithm will take extra time compared to simple search. So, never use sorting just to find a value in an array.

I advice against micro/premature optimization. It is useful to know which operations can slow down your program, but this knowledge must be used only when fine tuning, not while designing your code.

Only time/space complexity should be considered in advance, before you write any code.

--

--

Andrea Koutifaris
Andrea Koutifaris

Responses (1)