Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.02 2015S, Class 46: Binary Search Lab


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support (Afternoon Section)

Miscellaneous

Other Good Things (no extra credit)

Questions

Exploring the search API

;;; Procedure:
;;;   binary-search
;;; Parameters:
;;;   vec, a vector we're searching
;;;   key, the thing we're searching for
;;;   get-key, a procedure that extracts a key from an entry
;;;   may-precede?, a binary predicate (that tells you whether
;;;     the first argument can come before the second argument
;;;     in whatever ordering you're use)
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;    vec is not empty
;;;    vec is ordered by the column.  That is, for all "reasonable" i
;;;       (may-precede? (get-key (vector-ref vec i))
;;;                     (get-keyu (vector-ref vec (+ i 1))))
;;; Postconditions:
;;; Practica:
;;;    (binary-search campus-events-by-name "Contra Dancing"
;;;    (binary-search campus-events-by-location "Main"

Notes:

If it helps, here's a set of data, organized by event name

; Each event has name, location, date, expected audience
(define campus-events-by-name
  (vector (list "Contra Dancing" "Main" "2015-04-24" 60)
          (list "Convo-Memory" "JRC 101" "2015-04-22" 100)
          (list "Diversity as Artibrage" "Bucksbaum" "2015-04-24" 6)))
(define campus-events-by-name
  (vector 
   (list "Diversity as Artibrage" "Bucksbaum" "2015-04-24" 6)
   (list "Titular Head" "Harris" "2015-04-25")
   (list "Convo-Memory" "JRC 101" "2015-04-22" 100)
   (list "Contra Dancing" "Main" "2015-04-24" 60)))

Lab