Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Recursion

No description

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Recursion

void Dream()
{     
bool kick = CheckForKick();
     if(kick) 
return;
     
Dream();
}
Examples
Recursion
Problem => subproblems
HOW ??!!
int factorial(int n)
{
if(n == 0)
return 1;
else
return n*factorial(n-1);
}
string s = "Recursion";
void print(int i)
{
if(i == s.size())
{
cout << endl;
return;
}
cout << s[i];
print(i + 1);
}
Base Case
Recursive Call
Not all problems that are solvable with recursion are solvable with loop.
Dream Stack
Reverse it
void print(int i, string s)
{
if(i == s.size())
return;

print(i + 1, s);
cout << s[i];
}
Thank you
prepared by Abdelrahman Ihab
int fib(int n)
{
if(n == 0)
return 0;

if(n == 1)
return 1;

return fib(n-1) + fib(n-2);
}
Full transcript