improving program execution time

do recursive programs are less time taking than iterative ones??

definitely no, in languages like c++ where function calls are expensive.

I think it depends what problem you want to solve. Typically (my experience) it is easier to write recursive version, than iterative one, assume DFS as an exampleā€¦

1 Like

@alok4690:

Basically iterative ones are faster than recursive calls, because the function calls take some time compared to iterative ones where there is no function calls(but recursive functions are easier to write compared to iterative ones :slight_smile: )

Helpful links :

Wishes :slight_smile:

in c/c++, function call is expensive? i didnt know

nice posts.
http://www.job4india.in

nice postā€¦thanxā€¦
http://www.patialajokes.com/category/whatsapp-status/
http://www.healthbeautyblogs.com/health-home-remedies-health
http://www.healthbeautyblogs.com/articles-dry-fruits/how-charoli-is-helpful-to-us
http://www.healthbeautyblogs.com/articles-flours-benefits/assorted-benefits-of-sooji-for-health-and-diet
http://www.healthbeautyblogs.com/articles-flours-benefits/wholesome-benefits-of-cracked-wheat-or-dalia
http://www.healthbeautyblogs.com/articles-flours-benefits/healthy-benefits-of-poha-or-rice-flakes
http://www.healthbeautyblogs.com/articles-dry-fruits/multiple-benefits-of-sugar-candy-or-misri
http://www.healthbeautyblogs.com/articles-benefits-of-dairy-products/benefits-of-lassi-for-your-health
http://www.healthbeautyblogs.com/articles-amla-benefits/amla-powder-a-must-have-for-your-home
http://www.healthbeautyblogs.com/articles-dry-fruits/favorable-benefits-of-sultanas-and-currants
http://www.healthbeautyblogs.com/forums-benefits-of-nutrela
http://www.healthbeautyblogs.com/forums-mosambi-juice-benefits
http://www.healthbeautyblogs.com/articles-benefits-of-ginger/soonth-or-dry-ginger-benefits-for-health
http://www.healthbeautyblogs.com/articles-benefits-of-vegetables/ridge-gourd-benefits
http://www.healthbeautyblogs.com/articles-grains-benefits/benefits-of-soya-chunks-or-nutrela
http://www.healthbeautyblogs.com/forums-dry-amla-benefits-amla-candy

I think Recursive Programs are more taking than iterrative ones.
http://www.bestwishes4u.com/wishes-for/retirement-wishes/
http://www.bestwishes4u.com/wishes-for/sad-status-for-whatsapp/

thanx ā€¦nice postā€¦
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-bruises
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-vaginal-odor
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-black-eye-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-toothache
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-stomach-ache

http://www.healthbeautyblogs.com/tips/how-to-get-fair-and-glowing-skin-naturally
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-dandruff-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-bruises
http://www.healthbeautyblogs.com/tips/how-to-prevent-swine-flu-infection
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-vaginal-odor
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-gas
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-corns-on-feet
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-freckles
http://www.healthbeautyblogs.com/
http://www.healthbeautyblogs.com/tips/how-to-make-your-nails-grow-longer-and-faster
http://www.healthbeautyblogs.com/tips/how-to-get-baby-soft-skin-quickly
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-black-eye-fast
http://www.healthbeautyblogs.com/tips/multani-mitti-face-pack-for-glowing-skin-and-skin-whitening
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-toothache
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-razor-bumps-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-boil
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-bloating-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-hangover-fast

http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-runny-nose
http://www.healthbeautyblogs.com/tips/home-remedies-for-itchy-eyes
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-stomach-ache
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-ingrown-hair
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-stretch-marks-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-fever-blisters
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-diarrhea
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-fever
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-canker-sores-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-sunburn
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-nausea

@admin, ban this retard.

I agree with @betlista that writing a recursive function is, more often than not, more elegant. A recursive function also has the advantage of keeping the programmer at an abstract level, and avoid drowning him in implementation details. He/She can then focus on breaking the problem into smaller ones without getting a headache from ā€˜while loopsā€™.

But is a ā€˜while loopā€™ such a big headache? Recursion guarantees neither simplicity nor ease. Each line of recursive code requires deeper insight. Debugging is usually more painful, and the space/time required to allocate stack memory for each function call can make it infeasible.

It would be better if you check the problem constraints before deciding your final approach. At least, you can quickly work out the recursive function on paper. Dynamic programming and tail recursion in Scala can reduce the time required for a recursive algorithm tremendously. (Notice that Scala internally converts a recursive function to an iterative one, if you are nice enough to mention ā€œ@tail-recursiveā€.)

So, the answer is: no. Recursive algorithms usually take more time than iterative ones. But it is better to look at the situation before adopting/dumping it.

Best of Luck. :slight_smile:

1 Like

I agree with betlista and gkcs, recursive implementation isnā€™t always fast, rather it also requires stack memory so multiple recursive calls may result in exhausting of memory and regular function calls also requires transfer of flow of control so regular calls results in increased execution timeā€¦

Time expensed in multiple calls to recursive function which occurs due to transfer of control can be saved by making the function inlineā€¦ inline function are faster in C/C++, but there definition should be smallā€¦ for ex: inline recursive function for fibonacii series

1 Like

No, there is seldom a use for inlining function manually. The Compiler decides whether a function is to be inlined or not. Writing inline is just a hint. I think gcc/g++ doenā€™t care about this hint at all.

http://www.healthbeautyblogs.com/articles-home-remedies-for-skin-care/gram-flour-for-skin-whitening-and-for-glowing-skin
http://www.healthbeautyblogs.com/articles-flours-benefits/wholesome-benefits-of-cracked-wheat-or-dalia
http://www.healthbeautyblogs.com/articles-benefits-of-vegetables/ridge-gourd-benefits
http://www.healthbeautyblogs.com/articles-flours-benefits/reap-the-awesome-benefits-of-foxtail-millets
http://www.healthbeautyblogs.com/articles-flours-benefits/healthy-benefits-of-poha-or-rice-flakes
http://www.healthbeautyblogs.com/articles-benefits-of-dairy-products/benefits-of-lassi-for-your-health
http://www.healthbeautyblogs.com/articles-tulsi-benefits/different-types-of-tulsi-all-over-the-world
http://www.healthbeautyblogs.com/forums-dry-amla-benefits-amla-candy
http://www.healthbeautyblogs.com/articles-amla-benefits/how-to-make-dry-amla-candy
http://www.healthbeautyblogs.com/articles-dry-fruits/how-charoli-is-helpful-to-us
http://www.healthbeautyblogs.com/articles-dry-fruits/multiple-benefits-of-sugar-candy-or-misri
http://www.healthbeautyblogs.com/forums-benefits-of-pointed-gourd
http://www.healthbeautyblogs.com/articles-spices-and-herbs/various-benefits-of-mango-powder-or-amchur
http://www.healthbeautyblogs.com/forums-benefits-of-nutrela
http://www.healthbeautyblogs.com/articles-grains-benefits/benefits-of-soya-chunks-or-nutrela
http://www.healthbeautyblogs.com/articles-flours-benefits/assorted-benefits-of-sooji-for-health-and-diet
http://www.healthbeautyblogs.com/forums-benefits-of-shikakai
http://www.healthbeautyblogs.com/articles-benefits-of-ginger/soonth-or-dry-ginger-benefits-for-health
http://www.healthbeautyblogs.com/forums-mosambi-juice-benefits
http://www.healthbeautyblogs.com/articles-jaggery-benefits/9-amazing-health-benefits-of-jaggery-or-gur-benefits
http://www.healthbeautyblogs.com/articles-amla-benefits/amla-murabba-benefits
http://www.healthbeautyblogs.com/articles-home-remedies-for-stomach-problems/home-remedies-for-loose-motion
http://www.healthbeautyblogs.com/articles-benefits-of-dairy-products/health-benefits-of-buttermilk
http://www.healthbeautyblogs.com/articles-flours-benefits/nutritious-benefits-of-wholesome-aatta-mix
http://www.healthbeautyblogs.com/tips/multani-mitti-face-pack-for-glowing-skin-and-skin-whitening
http://www.healthbeautyblogs.com/articles-body-care-tips/how-to-get-rid-of-upper-lip-hair
http://www.healthbeautyblogs.com/articles-amla-benefits/amla-powder-a-must-have-for-your-home
http://www.healthbeautyblogs.com/forums-amla-juice-benefits
http://www.healthbeautyblogs.com/articles-home-remedies-for-skin-care/benefits-of-multani-mitti-for-hairs-and-skin-be-a-glowing-beauty
http://www.healthbeautyblogs.com/articles-benefits-of-vegetables/health-benefits-of-ash-gourd
http://www.healthbeautyblogs.com/articles-flours-benefits/ragi-health-benefits-for-happy-life
http://www.healthbeautyblogs.com/articles-dry-fruits/watermelon-seeds-benefits
http://www.healthbeautyblogs.com/tips/benefits-of-fenugreek-seeds-or-meethi-seeds-for-your-skin-hairs
http://www.healthbeautyblogs.com/articles-grains-benefits/benefits-of-black-beans
http://www.healthbeautyblogs.com/tips/how-to-get-fair-and-glowing-skin-naturally
http://www.healthbeautyblogs.com/articles-dry-fruits/favorable-benefits-of-sultanas-and-currants
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-razor-bumps-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-dandruff-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-toothache
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-a-hangover-fast
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-vaginal-odor
http://www.healthbeautyblogs.com/articles-home-remedies-for-hair-and-skin-care/flax-seeds-benefits-for-health-hair-skin

http://www.healthbeautyblogs.com/forums-benefits-of-nutrela
http://www.healthbeautyblogs.com/forums-mosambi-juice-benefits
http://www.healthbeautyblogs.com/articles-benefits-of-dairy-products/health-benefits-of-buttermilk
http://www.healthbeautyblogs.com/articles-home-remedies-for-stomach-problems/home-remedies-for-loose-motion
http://www.healthbeautyblogs.com/articles-jaggery-benefits/9-amazing-health-benefits-of-jaggery-or-gur-benefits
http://www.healthbeautyblogs.com/tips/how-to-get-baby-soft-skin-quickly
http://www.healthbeautyblogs.com/tips/benefits-of-fenugreek-seeds-or-meethi-seeds-for-your-skin-hairs
http://www.healthbeautyblogs.com/tips/how-to-get-fair-and-glowing-skin-naturally
http://www.healthbeautyblogs.com/tips/multani-mitti-face-pack-for-glowing-skin-and-skin-whitening
http://www.healthbeautyblogs.com/articles-body-care-tips/how-to-get-rid-of-upper-lip-hair
http://www.healthbeautyblogs.com/tips/how-to-make-your-nails-grow-longer-and-faster
http://www.healthbeautyblogs.com/tips/how-to-remove-blackheads-from-nose
http://www.healthbeautyblogs.com/forums-amla-juice-benefits
http://www.healthbeautyblogs.com/articles-dry-fruits/watermelon-seeds-benefits
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-onion-breath-with-home-remedies
http://www.healthbeautyblogs.com/tips/how-to-get-fair-and-glowing-skin-naturally
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-dandruff-fast
http://www.healthbeautyblogs.com/articles-amla-benefits/amla-powder-a-must-have-for-your-home
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-razor-bumps-fast
http://www.healthbeautyblogs.com/articles-home-remedies-for-skin-care/benefits-of-multani-mitti-for-hairs-and-skin-be-a-glowing-beauty
http://www.healthbeautyblogs.com/tips/how-to-get-rid-of-bloating-fast
http://www.healthbeautyblogs.com/articles-home-remedies-for-skin-care/gram-flour-for-skin-whitening-and-for-glowing-skin
http://www.healthbeautyblogs.com/desi-gharelu-nuskhe/nimbu-aur-nimbu-pani-ke-anginat-fayde
http://www.healthbeautyblogs.com/gharelu-nuskhe.htm
http://www.bestwishes4u.com/wishes-for/retirement-wishes/
http://www.bestwishes4u.com/wishes-for/condolence-messages/
http://www.bestwishes4u.com/wishes-for/marriage-wishes-sms/
http://www.bestwishes4u.com/
http://www.bestwishes4u.com/best-fb-status-updates/
http://www.bestwishes4u.com/best-inspirational-and-motivational-quotes-and-sayings/
http://www.bestwishes4u.com/best-whatsapp-group-names-ideas/
http://www.bestwishes4u.com/death-condolence-sms-messages/
http://www.bestwishes4u.com/good-morning-sms-wishes-messages-and-quotes/
http://www.bestwishes4u.com/good-night-sms-wishes-messages-and-quotes/
http://www.bestwishes4u.com/happy-birthday-wishes-sms-and-quotes/
http://www.bestwishes4u.com/best-whatsapp-status-fb-status-quotes-and-sms/
http://www.bestwishes4u.com/marriage-anniversary-wishes-sms-and-messages/
http://www.bestwishes4u.com/retirement-wishes-sms-and-messages/
http://www.bestwishes4u.com/cute-dosti-romantic-love-sweet-relationship-sms-and-messages/

http://www.healthbeautyblogs.com/dadi-maa-ke-desi-gharelu-nuskhe.htm
http://www.healthbeautyblogs.com/desi-gharelu-nuskhe/janiye-nimbu-ke-anek-fayde-nimbu-mai-chipe-hai-kai-healthy-raaz
http://www.healthbeautyblogs.com/desi-gharelu-nuskhe/dadi-maa-ke-desi-gharelu-nuskhe-or-upchar-for-headaches