---
title: Eboard 34  Binary search
number: 34
section: eboards
held: 2018-04-23
link: true
---
CSC 151.01, Class 34:  Binary search
====================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Questions
* Tutor/mentor evaluations
* Lab

Preliminaries
-------------

### News / Etc.

* New partners!
* Note: You do not get EC if you participate in an event.  The EC is for
  people who come to support you.
* I apologize for missing Friday's PSA.  I hope that you all got sufficient
  sunshine on Sunday!
* We have tutor/mentor evaluations today.  Please take them seriously;
  they help us improve the program.
* SamR will, on occasion, write helper code for your projects.

### Upcoming work

* [Project Proposal](../assignments/project) due **TONIGHT** at 10:30 p.m.
* [Lab writeup for class 34](../writeups/writeup34): Exercise 4.
  Due Wednesday.
* No reading for Wednesday.
* [Flash Cards](../flashcards/flashcards12) due next Wednesday at 9pm.
    * Optional.
    * Grade is percent of eight flashcard assignments you complete 
      (capped at 100%).

### Extra credit (Academic/Artistic)

* Diversity in Filmmaking, Monday, 4:15 p.m., Bucksbaum 152
* Squire Lecture in Physics, Tuesday at 11:45: STEM Eqwuality and Inclusion, a
  Female Astronomer's View.  Noyce 1023.
* CS Table Tuesday noon in Day PDR: One Laptop Per Child.
* The Cypher Paradigm: Closing Cypher, Tuesday, 8:30 p.m., ARH 120.
* Vance Byrd Book Talk Thursday at 4:15 pm, Burlilng 1st Floor Lounge

### Extra credit (Peer)

* Escape Room, 7-9pm TONIGHT, Gates
* Thursday, April 26th, Noyce 2022: Mellon Mays Project introductions, 
  4:15 to 6:30 p.m.
* Friday, 8pm, Main: Contra Dance
* Dance Ensemble Thursday 7:30pm, Friday 7:30pm, Saturday 7:30pm, Sunday 2pm.
  Roberts.  Tickets go "on sale" today.
* Open Mike Thursday 9-11pm in Bob's.

### Extra credit (Recurring peer)

* Listen to KDIC Wednesdays at 6pm - Witty banter with other 
  personalities and/or co-host.  Also Indian, Arabic, and Farsi music.  
  (Up to two units of extra credit.)
* Listen to KDIC Thursday at 7pm - Classic Rock.  (60's and 70's)
* Peer editing with SS.  Talk to SS about the details.  Make your
  English Lit more literate.

### Extra credit (Misc)

* Any Sexual Assault Awareness Month event.

### Other good things

### Questions

_How should I have approached problem 1 on the quiz?_

* Problem 1 on the quiz was a "file recursion" problem.  How do you process
  all of the data in a file?
* You need to do all of the following
    * Open the file for reading. `open-input-file`, parameter is the name
      of the file.
        * The name of the file is a string.  If you are giving a particular
          file, put it in quotation marks.  If not, just use the variable
          name.
    * Read data again and again and again with a recursive kernel.
      There are three procedures
        * `peek-char` to look at the next character but not "consume" it.
          (You will still have to read or you will recurse forever.)
        * `read-char`, to read the next character
        * `read`, to read a Scheme value.  (number, string, symbol, list)
    * Stop when you reach the end of the file.  The thing you read is an
      eof-object.
    * Close the port.
    * Return the value you computed (potentially with a little post-processing)

```
(define file->nums
  (lambda (fname)
    (let ([inport (open-input-file fname)])
      (let kernel ([numbers null])
        (let ([next (read inport)])
          (cond
            [(eof-object? next)
             (close-input-port inport)
             (reverse numbers)]
            [(number? next)
             (kernel (cons next numbers))]
            [else
             (kernel numbers)]))))))
```

_Can you explain this `get-key` thing?_

* When we are searching a list of objects, there is some characteristic of
  each object that we are looking for.
* `get-key` is the procedure that extracts that piece of information from
  each object.
* If we are searching a list of students for someone with a particular
  name. `get-key` extract the name.
* If we are searching a list of students for someone with a particular
  major. `get-key` extract the major.

Tutor/Mentor Evaluations
------------------------

Thank you for taking the time to fill these out.

Lab
---

Writeup: Exercise 4.

Hint: Try running the algorithm by hand on a three-element (or four-element
vector).

* Vector: 0: Sally, 1: Sam, 2: Shelby
* Search for Ella
    * lb: 0, ub: 2.  midpoint is 1.  That's Sam.  Sam comes after Ella.
      So the new ub is midpoint-1, or 0.
    * lb: 0, ub: 0.  midopint is 0.  That's Sally.  Sally comes after Ella.
      So the new ub is midpoint-1, or -1
    * lb: 0, ub: -1.  Stop.  We want to return -1/2.
* Search for Titus.
    * lb: 0, ub: 2.  midpoint is 1.  That's Sam.  Sam comes before Titus.
      So the new lb is midpoint+1, or 2.
    * lb: 2, ub: 2.  midpoint is 2.  That's Shelby.  Shelby comes before Titus.
      So the new lb is midpoint+1, or 3.
    * lb: 3, ub: 2.  Stop.  We want to return 2.5 (or 2 1/2)
* Search for Sarah
    * lb: 0, ub: 2.  midpoint is 1.  That's Sam.  Sam comes before Sarah.
      So the new lb is midpoint+1, or 2.
    * lb: 2, ub: 2.  midpoint is 2.  That's Shelby. Shelby comes after Sarah
      So the new ub is midpoint-1, or 1.
    * lb: 2, ub: 1.  Stop.  We want to return 1.5 (or 1 1/2)
* Do you see a pattern?

