University of Virginia, Department of Computer Science
CS200: Computer Science, Spring 2004

Notes: Monday 26 January 2004
Schedule

Recursive Definitions

  1. Be optimistic.
    • Assume you can solve it.
    • If you could, how would you solve a bigger problem.
  2. Think of the simplest version of the problem, something you can already solve. (This is the base case.)
  3. Combine them to solve the problem.


(define (find-closest goal numbers)
   (if (= 1 (length numbers))
       (first numbers)
       (if (< (abs (- goal (first numbers)))
	      (abs (- goal 
		      (find-closest goal (rest numbers)))))
           (first numbers)
           (find-closest goal (rest numbers))))

Languages

How can we compare notations for describing languages?






What is the difference between RTN and BNF?

Music and Recursion

Song ::= Verse VBBD VBBD Better Coda
VBBD ::= Verse Bridge Bridge Dadada (ends on C)
Coda ::= F Eb Bb F Coda
Note: the Coda has no base case, and should continue forever (time permitting).
Challenge Problem
Define a Scheme procedure that can produce the INT and Gplot graphs from GEB Chapter 5. Hint: you may need to think about curves differently from PS2. (A solution is worth two gold stars.)

Links

Hofstadter's Law: It always takes longer than you expect, even when you take Hofstadter's Law into account.
CS200 Law: Problem Sets always take longer than you expect, even when you take the CS200 Law into account.

cs200-staff@cs.virginia.edu
Using these Materials