3 ms·
This process would be satisfied with a linear search. To even just see that there is a log n algorithm in the case where the input is sorted, you need to think
by mannykannot 5y ago
This process would be satisfied with a linear search. To even just see that there is a log n algorithm in the case where the input is sorted, you need to think analytically about the problem and its solution.
Suppose the problem is presented with runtime constraints for some sufficiently large test cases, such that this difference in performance matters. Even in that case, what are the chances that a TDDer who is unaware of the binary search algorithm will stumble on the correct solution, while never looking beyond the next test to be satisfied? In the small cases, the difference is not discernible. I suggest that to be successful, one must think analytically about the problem, and code to the insights revealed by that analysis, in addition to the specifications themselves.
A lot of problems are like that - e.g.:
http://ravimohan.blogspot.com/2007/04/learning-from-sudoku-solvers.html http://ravimohan.blogspot.com/2007/04/learning-from-sudoku-s...
- baobabKoodaa 5y agoAgreed. The idea that a developer would start coding with TDD and subsequently arrive at a O(n log n) solution that works on all edge cases is... fantasy to put it mildly.
- baobabKoodaa 5y ago*this is supposed to say O(log n)