DOC PREVIEW
MIT 6 001 - Orders of Growth

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.001, Spring 2006—Recitation 5 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsSpring 2006Recitation 5More Orders of GrowthSpecial Forms1. begin - (begin expr1 expr2 ... exprn)First evalutate expr1, then expr2, and so on. The value of the begin statement is the valueof the last expression in the sequence.2. let - (let ((name1 val1) (name2 val2) ... (namen valn)) body)Syntactic sugar for the following:((lambda (name1 name2 ... namen) body) val1 val2 ... valn).Used to bind additional names inside a procedure body.Typical Orders of Growth: Review• Θ(1) - Constant growth. Simple, non-looping, non-decomposable operations have constantgrowth.• Θ(log n) - Logarithmic growth. At each iteration, the problem size is scaled down by aconstant amount: (call-again (/ n c)).• Θ(n) - Linear growth. At each iteration, the problem size is decremented by a constantamount: (call-again (- n c)).• Θ(n log n) - Nifty growth. Nice recursive solution to normally Θ(n2) problem.• Θ(n2) - Quadratic growth. Computing correspondence between a set of n things, or doingsomething of cost n to all n things both result in quadratic growth.• Θ(2n) - Exponential growth. Really bad. Searching all possibilities usually results in expo-nential growth.Problems1. (define (fact n)(if (= n 0)1(* n (fact (- n 1)))))Running time? Space?6.001, Spring 2006—Recitation 5 22. (define (find-e n)(if (= n 0)1.(+ (/ (fact n)) (find-e (- n 1)))))Running time? Space?3. Assume you have a procedure (divisible? n x) which returns #t if n is divisible by x. Itruns in O(n) time and O(1) space. Write a procedure prime? which takes a number andreturns #t if it’s prime and #f otherwise. You’ll want to use a helper procedure.Running time? Space?4. Write an iterative version of find-e.Running time? Space?5. Write a version of sum-by-halves (from your problem set) that only computes the midpointbetween a and b once per iteration.Running time?


View Full Document

MIT 6 001 - Orders of Growth

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Orders of Growth
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Orders of Growth and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Orders of Growth 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?