Upcoming Schedule
- Wednesday, 30 September (10:01am): Problem Set 4
- Wednesday, 6:30-8pm in Olsson 001: ACs' Review Session
- Thursday, 1:30-3pm in Olsson 236A: Extra Office Hours
- Friday, 2 October: Exam 2 out
- Wednesday, 7 October (10:01am): Exam 2 due
Exam 1
Exam 1 will be distributed shortly after the end of class Friday, and
due at 10:01am on Wednesday, October 7.
It will cover all of the material in the course through Class 16
(Wednesday, 30 Sept) including:
The exam will emphasize understanding the main concepts we have seen in
all three of the problem sets, classes, and course book.
To prepare for Exam 1:
- Review any material you are confused on from PS1-4.
- Try the practice
exams from previous courses.
- Try exercises in the course book.
Review Session. The ACs will hold a review session Wednesday, 6:30-8pm in Olsson 001
(this is in place of the normal Help Hours scheduled for Wednesdays).
Office Hours. In addition to my regularly scheduled office hours Monday and Tuesday
mornings, I will have additional office hours Thursday 1:30-3pm in
Olsson 236A. If none of these times work for you, email me to schedule
an appointment.
Analyzing Running Time
(define (flatten-commands ll)
(if (null? ll) ll
(if (is-lsystem-command? (car ll))
(cons (car ll) (flatten-commands (cdr ll)))
(flat-append (car ll) (flatten-commands (cdr ll))))))
(define (is-lsystem-command? lcommand)
(or (is-forward? lcommand)
(is-rotate? lcommand)
(is-offshoot? lcommand)))
(define (flat-append lst ll)
(if (null? lst) ll
(cons (car lst) (flat-append (cdr lst) ll))))
What is the asymptotic running time of
flatten-commands?
Analyzing Recursive Procedures
To determine the asymptotic running time for a recursive procedure:
- Determine the running times of all other procedures applied
in the body.
- Introduce variables to represent the size of the inputs (e.g., N).
- Determine the asymptotic running time for the procedure body except for
the recursive call (e.g., in Θ(R(N))). If the running
time of the body varies over the calls, think carefully about whether
you need to use the worst case or average case running time.
- Determine the number of recursive calls (e.g., K(N)).
- The overall running time is in Θ(R(N) K(N)).
(define (insert-sort lst cf)
(if (null? lst) null
(insert-one (car lst) (insert-sort (cdr lst) cf) cf)))
(define (insert-one el lst cf)
(if (null? lst) (list el)
(if (cf el (car lst)) (cons el lst)
(cons (car lst) (insert-one el (cdr lst) cf)))))