# Recursion - PowerPoint PPT Presentation

PPT – Recursion PowerPoint presentation | free to download - id: 74d98f-ODVlZ

The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
Title:

## Recursion

Description:

### Recursion 1. The computer science equivalent of mathematical induction. 2. A way of defining something in terms of itself. 3. Ex. f(n) = 1, if n ==1 – PowerPoint PPT presentation

Number of Views:5
Avg rating:3.0/5.0
Slides: 3
Provided by: tcnjEdu7
Category:
Tags:
Transcript and Presenter's Notes

Title: Recursion

1
Recursion
1. The computer science equivalent of
mathematical induction.
2. A way of defining something in terms of
itself.
3. Ex. f(n) 1, if n 1
f(n) n f(n - 1), if n gt 1
10
4. Ex. f(4) 4 f(3)
6
f(3) 3 f(2)
f(2) 2 f(1)
3
f(1) 1
5. f(4) 4 3 2 1
2
Ex. n 6 1 2 3 4 5 6 (1
6)(6/2)
7. Can we get the same output without recursion?
8. Yes. Always. Using loops.
9. Rewrite WhatItDo() without recursion.
10. Recursion shortens code but may take a great
deal more computer time and space, sometimes
causing stack overflow. Therefore, only use
recursion when it helps solve a problem.