CSC151.01 2014F, Class 43: Analyzing Procedures
===============================================

*Continue partners.*

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Short pre-brief
* Lab
* Debrief (if time)

Preliminaries
-------------

### Admin

* Project sketches due!
    * I plan to comment on your proposals and sketches tonight.
* Quizzes likely returned tomorrow.  (I had four hours reserved for work 
  this a.m.; three got used for administrative work.)
* Reminder: Review sessions on Wednesday and Thursday!

### Upcoming Work

* No lab writeup.
* Reading for Wednesday:
    * [Association Lists](../readings/association-lists-reading.html)
* Part two of the project due next Tuesday.
* Nothing due the week after Turkey break.  
    * We may distribute exam 4 next Wednesday for those who want to
      use break time to work on the exam.  But it will be designed as 
      if we distributed it immediately after break.

### Extra Credit Opportunities

#### Academic

* CS Extras Thursday: Text Recognition in Maps
* CS Table Friday: One Year After Healthcare.gov
* CS Extras Tuesday the 25th: Summer Opportunities in CS

#### Peer Support

* Karan's radio show 11pm Thursday nights on KDIC
* Evan's radio show 5pm Friday nights on KDIC 
* Donna's radio show Sunday midnight on KDIC
* One acts, coming soon
* Swimming and Diving at Loras on Saturday

#### Miscellaneous

* SHACS Open House, Today, 4-5pm.
  "If you have nay questions or concerns about the changes in SHACS,
  come to their open house."
* VP Student Affairs Candidate Open Sessions
    * Wednesday, 4:15, JRC 209
    * Friday, 4:15, JRC 209

### Questions

Prebrief
--------

Key points of the reading?

* Procedures can be more or less efficient.
* We should try to make our procedures more efficient.
* We can figure out efficiency by counting steps (e.g., number of calls)
* We can use vectors to implement those counters.

What was confusing?

_Using counters makes sense, but I don't get how they work_

> We set up one counter per procedure.

> That means we need things that change.

> Vectors allow us to change.  Each counter is a one element vector
  where the element is the count (of calls to the corresponding procedure).

        (vector-set! vec 0 (+ 1 (vector-get! vec 0)))

> Once you know how to do something, you don't rewrite the complex code,
  you name it as a procedure.  `counter-increment!`

_I don't get the difference between linear time and constant time_

> Terms for efficiency.

> Linear time: You do a number of calls approximately proportional to
  the size of input elements (e.g., the number of elements in a list).

> Constant time: Independent on the size of the input.  car takes only
  one step, whether it's 100 elements or 1000 elements or 10000000 elements.

_Explain all of the `counter-x` procedures.  How do we integrate them_

> Setup: Outside the procedure

        (define PROC-counter (counter-new "procedure"))

        (define member?-counter (counter-new "member?"))

> Setup: Inside the definition of the procedure

        (counter-increment! PROC-counter)

        (define member?$
          (lambda (val lst)
            (counter-increment! member?-counter)
            (and (not (null? lst))
                 (or (equal? (val (car lst)))
                     (member?$ val (cdr lst))))))

> Analysis

        (counter-reset! member?-counter)
        (member?$ 1000 (iota 1000))
        (counter-print! member?-counter)

        (counter-reset! member?-counter)
        (member?$ -1 (iota 1000))
        (counter-print! member?-counter)

Lab Reflections
---------------

* One more extra credit thing: SHACS open house today, 4-5pm.
* Did you think about why one version of reverse took so much more 
  time?  Did you try a larger list?



