CSC 110 Lecture Notes - Lecture 12: Tuple, Backtracking, Stack Overflow

54 views5 pages

Document Summary

Chapter 5 review: 2 different ways to create a function, def, object oriented languages only use this one, uses an equal sign. In scala: def fact(n:int):int = if(n<2) 1 else n*fact(n-1, eventually runs out of room so to fix this, if you need to, change the int into a long to give you more space. In scala: def mult(m: int, n:int):int = if(n==0) 0 else m+mult(m, n-1, recursion iteration, recursive function calls itself. 10/9/14: for recursion to be successful, the problem must keep shrinking, work must be done for every step until base case is reached, breaking down function into smaller and smaller pieces of data. If called by value, n is copied into x and the copy is changed not the original: call by value will not change the value of the original. Compares whether to is: direct recursion less than or greater than from, when a function calls itself directly, f calls f.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents