Functional Problem Solving (CSC 151 2014F) : EBoards

CSC151.01 2014F, Class 43: Analyzing Procedures


Continue partners.

Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

Questions

Prebrief

Key points of the reading?

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