Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Review Session 14 (2016-05-12)


No one showed up. All you get are my preliminary notes.

Overview

About the final

Problem 1: Is it sorted?

Key idea: Use vector recursion.

(define vector-proc
  (lambda (vec)
    (let kernel ([pos 0])
      (cond
        [(= pos (vector-length vec)) ; Or something similar
         base-value]
        [(another-test)
         base-value]
        [else
         (kernel (+ pos 1))]))))

We are returning a Boolean.

What should our base values be?

Problem 2: Whatzitdo?

We've seen something similar on an exam (or at least I think we have).

Problem 3: Is it efficient?

We know that append requires 1 call to cons for each value in the first list.

So, to reverse a list of length n using list-reverse-1 ...

So 1+2+3+...+n, which we now know is n(n+1)/2.

Alternately, you could work out the steps by hand.

Problem 4: Nesting

Other Questions

There were none.