What would be an example of using recursion (with little explanation and/or code sample)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Uses: Parsing; traversal; generating fractals; some forms of encryption
Examples: Towers of Hanoi; Fibonacci Seq; Subset generation (there are tons of examples, I can code a few of these for you if you want?)
Advantages: Simple; Intuitive for certain problems (e.g. Ackermann function, traversal)
Disadvantages: Slow (although you can implement any recursive solution using stacks); May result in stackoverflow exception
In case, anyone is wondering about encryption, here is a short explanation of Cipher Block Chaining Mode:
[adapted from Bruce Shneier’s excellent book, Applied Cryptography]