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 of something
;;; key, a value
;;; get-key, a unary procedure
;;; may-precede?, a binary predicate (or comes-before?)
;;; Purpose:
;;; Produces:
;;; Preconditions:
;;; vec is ordered by key. That is, for all reasonable i,
;;; (may-precede? (get-key (vector-ref vec i))
;;; (get-key (vector-ref vec (+ i 1))))
;;; Postconditions:
A few quick examples
; Each event has a name, a location, and an expected attendance
(define events-on-campus
(vector
(list "CS Table" "Day PDF" 10)
(list "Convo: Personal Memory" "JRC 101" 150)
(list "Titular head" "Harris Cinema" 1800)))
If ordered by capacity
(binary-search events-on-campus 150 (o car cdr cdr) <=)
If ordered by title
(binary-search events-on-campus "Titular Head" car string-ci<=?)
If we use vectors rather than lists, ordered by capacity ; Each event has a name, a location, and an expected attendance (define events-on-campus (vector (vector "CS Table" "Day PDF" 10) (vector "Convo: Personal Memory" "JRC 101" 150) (vector "Titular head" "Harris Cinema" 1800)))
(binary-search events-on-campus 211 (r-s vector-ref 2) <=)
(binary-search events-on-campus 211 (lambda (event) (vector-ref event 2)) <=)