Recursion - PowerPoint PPT Presentation

About This Presentation
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:60
Avg rating:3.0/5.0
Slides: 3
Provided by: tcnjEdu7
Category:

less

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.
Write a Comment
User Comments (0)
About PowerShow.com