CSC151 2007S, Class 28: Analyzing Procedures Admin: * Reminder: Assignment 11 is now due Friday * SAM NEEDS TO FIGURE OUT WHAT'S GOING WRONG WITH test-permutation! * EC to Abby, Dylan, Matt, Carter for dealing with the problems * Sniff. Missing a student. * Reading for Thursday: Numeric Recursion. * EC: Thursday at 4:30, Ian Young talks about regular expressions in VIM * Other issues: * STUDENTS WOULD LIKE A REVIEW OF HUSK-AND-KERNEL * Sam needs to tell the story of how you compute 1 + 2 + 3 + ... + N Overview: * Comparing algorithms. * Two related metrics: Time and Number of steps. * Counting procedure calls by printing. * Tools for analysis. A few observations: * Given a particular problem, there are often many algorithms we can write to solve it. * How do we choose which one to use? What criteria might we use? * Resource consumption: How much computing power and time does it use? * Related to time is "number of steps". * Something with more steps is likely to take more time. * E.g., if something takes 1000 steps, it's likely to be much slower than something that takes 100 steps. * But not always: 1000 additions are quicker than 100 square roots * Readability/Understandability * Number of lines * Generality: Does it solve just this problem, or many related problems * At different times, you will prioritize different criteria * We tend to prioritize "running time" (measured in wall-clock or steps) * But only once the correctness problem is solved Analysis is useful for other reasons, too: Why does this algorithm seem so slow? Let's define count-odds * Defined * Added precondition testing (define count-odds (lambda (lst) (display (list 'count-odds lst)) (newline) (if (not (list? lst)) (throw "count-odds: I refuse to work for people who do not understand what lists are.") (if (not (all-integers? lst)) (throw "count-odds: I only like lists of integers") (if (null? lst) 0 (+ (if (odd? (car lst)) 1 0) (count-odds (cdr lst)))))))) * Observation: Much slower than it should be (okay, we pretended to observe this).