3 ms·
That's because you're taught recursion is bad/difficult, and you're probably operating at the bucket and pointer level of abstraction. Binary search, and more
by mahmud 17y ago
That's because you're taught recursion is bad/difficult, and you're probably operating at the bucket and pointer level of abstraction.
Binary search, and more specifically recursion over lists and trees, and the logical reasoning over with induction is one of the most primitive skills one acquires while learning Lisp.
- FutureNerd 17y agoI have to say that the usual way of writing binary search recursively doesn't help break the problem down. It's already as broken down as it gets, and you're just tweaking the single case. The loop version wins for clarity. I think second runner-up is the recursive version where you use slices... does lisp have slices?
- eru 17y agoLoops are just special cases of recursion. And binary search is definitely not the right operation on linked lists. So even in Lisp you should use a different data structure if you want to do a binary search.