CS116 Chapter 3: Module 3 (Racket/Scheme) - Accumulative Recursion

127 views3 pages
2 Mar 2016
Course
Professor

Document Summary

Understand how to write accumulative recursive functions to build or accumulate a solution. Understand constant, linear, quadratic, and exponential running times. Understand how to analyze basic recursive code to determines its running time. Understand how accumulative recursion may allow for substantial ef ciency gains. Understand how to test accumulative recursive code. Template for code is based on recursive de nition of the data (ex. basic list template) ex. ;; (factorial n) produces the product of the integers from 1 to n. ;; examples: (check-expect (factorial 1) 1) (check-expect (factorial 5) 120) (de ne (factorial n) (cond [(<= n 1) 1] ** all multiplications are done once you reach the end, then it builds back up to the rst element, evaluating along the way. Accumulative recursion ex. (de ne (factorial n) (local [(de ne (running-product n0 prod-so-far) (cond [(<= n0 0) prod-so-far] [else (running-product (sub1 n0) (* prod-so-far n0))]))] (running-product n 1)))

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents