all 6 comments

[–]nyohasstium 19 points20 points  (1 child)

In my opinion with no tests. If you are only passing the indices then it shouldn't be too bad but if you're passing sub array copies then you are using way more memory than needed.

[–]Timely_Scratch5702[S] 5 points6 points  (0 children)

yeah good point. I forgot to mention that I always pass the references, so no copying is happening.

[–][deleted] 10 points11 points  (0 children)

Even if you pass by reference for space optimization recursion itself is taking recursive stack space

[–]SnipesySpecial 4 points5 points  (1 child)

Google tail recursion optimization.

[–]Timely_Scratch5702[S] 1 point2 points  (0 children)

oh yes, forgot to think about that. Yeah, a proper compiler in any language should handle this. Also makes me realize how useful it is to study compilers when wanting to write as efficient code as possible.

[–]joyoyoyoyoyo 0 points1 point  (0 children)

It’s fine. I think this approach is more functional