|
|
|
|
|
by lucio
4211 days ago
|
|
Thanks. As I said in my comment I know my ignorance and I'm looking for enlightenment (my confession didn't stop the downvotes though) I do not "see" any clear algorithm in the code (no step-by-step procedure). I see recursion only. ¿Can you explain in words what this code is doing? ¿Can you implement this without using recursion? |
|
Using that example list above ([3, 5, 1, 4, 2]), here's if we did it by hand:
That "step-by-step procedure" is an algorithm.Is it that there are no loops that you don't see how it's an algorithm? It is definitely true that some algorithms are very obvious to implement using loops (quicksort is actually one such algorithm), and can in fact be a pain in the neck to implement in some functional languages.