[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

recursion/tail recursion

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 6
Thread images: 1

File: quicksort.png (5KB, 324x114px) Image search: [Google]
quicksort.png
5KB, 324x114px
How do I make this recursive?
This is tail recursive, which is much better I'm trying to find ways to make tail recursive recursive and vice versa and I don't know how.
I've understood how to make recursive functions iterative but I for some reason cant tell the difference between recursion/tail recursion
>>
>>337567
That's because tail recursion is a type of recursion.

Literally the only difference is that tail recursion is recursion where there's only one call, with no code that changes the state after it. This lets the compiler/interpreter get away with not using a stack, because there's no (meaningful) instructions to jump back to, so it can jump straight back to whatever called the tail-recursive function.

You're not going to see a tail-recursive sort, because the whole point of a recursive sort is that it partitions the search space by calling itself more than one time.
>>
>>337574
Is it even possible to make this non-tail recursive then?
>>
>>337581
It's already non-tail-recursive, because it calls itself twice.

If you want to make anything from tail-recursive to not tail-recursive, just do anything with a side-effect after the recursive call. The compiler can't just remove side-effects, so it has to keep a stack so all the side-effects happen.
>>
>>337593
Wouldnt it be recursive if it was:

return Quicksort(A,p,q-1) + Quicksort(A,q+1,r) ?
>>
>>337598
In what scenario would that return make sense? Quicksort is an in-place algorithm.
Thread posts: 6
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.