Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
assoc,
and searching.;;; 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)))