---
title: Eboard 33  Linear and binary search
number: 33
section: eboards
held: 2019-04-24
link: true
---
CSC 151 2019S, Class 33:  Linear and binary search
==================================================

_Overview_

* Preliminaries
    * Notes and news
    * Upcoming work
    * Extra credit
    * Questions
* Analyzing algorithm efficiency
* The problem of searching
* Divide and conquer
* Destructive binary search (a demonstration)
* Lab

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

### News / Etc.

* Warning! I think today sets a record for the length of the preliminaries.
* Mentor sessions Thursday 7-8 p.m., Thursday 8-9 p.m.
    * Note change in schedule (Sunday session dropped until review for final)
* The College has decided to institute electronic end-of-course evaluations.
  You should be getting information about them next week.  We will do
  evaluations in class on the last day of class, so you should not be able
  to access this class's EOCEs before then.  Because we have fewer computers
  than students, it would be helpful if some of you brought smart devices
  (laptops, tablets, cell phones to the last class).
* Next week's Science Teaching and Learning Group will discuss student
  wellness.  I'm hoping to share some of the extra credit reports you've
  submitted (anonymously).  Let me know if you object to me sharing yours.
* Folks should think about taking CSC 161 in the fall.  It's a great class,
  and you get to work with robots! 
* Folks should also think about taking HIS 295, which approaches some of the topics of this course from a very different perspective.

    > _HIS 295 Digital History: Investigating the Past_. This course will introduce students to methods used in the digital humanities, with a special emphasis on applications to historical studies. Students will create projects and study existing digital projects, with a special focus on U.S. History in a global context. Readings will include primary sources as well as recent contributions to theory in digital humanities. We will learn general principles of working with humanistic data as well as techniques such as building on-line exhibitions, digital mapping, and computational analysis of text. No technical skills or experience in digital humanities work are required, but willingness to gain both are fundamental to the class. Prerequisite: HIS-100 or second-year standing.

* For those considering a technology studies concentration, this is what
  I know (or some of what I know).
    * You will not be able to declare a technology studies concentration after
      Fall 2019.  It's going away.  But if you declare by then, we'll do our
      best to let you finish the concentration.
    * Technology studies is being replaced by a new concentration in
      Science and Medicine Studies, which should go online about the
      time TechStudies goes away.  There is likely to be significant
      overlap between the concentrations.
    * We expect that there will also be a Digital Studies concentration
      which also helps supplement tech studies.
    * TEC 154, the core course in Tech Studies, will not be offered next
      year.  Students may count CSC 105 in its stead.  (You might be
      able to argue to count HIS 295 in its stead.)
    * We're not even sure about TEC 154 the following year, but we're
      hopeful.

### Upcoming work

* [Project](../project) due Tuesday!
    * [Rubric](../project/rubric.txt) available for your perusal.
* Friday's quiz: Higher-order procedures, algorithm analysis, deep recursion
* No reading for Friday; Friday is a project work day.
* Flash cards tonight: Higher-order procedures, algorithm analysis, trees.
* Lab writeup: Problem 1c. (Class 33)

### Extra Credit

_I would certainly appreciate suggestions of other extra credit activities
(preferably via email)._

#### Extra credit (Academic/Artistic)

* **New**/**Today**: Get to Know Grinnell, Noon, JRC 101 (Sarah Purcell and
  Henry Rietz discuss the transition from student to faculty)
* **Today**: Dartanyan Brown discussion, 4pm Wednesday April 24, HSSC S3325
* **Today**: Dartanyan Brown concert, 7:30 pm Wednesday April 24, Sebring-Lewis
* **Tomorrow**: PBK Convo, Thursday, 11am: "Antievolutionism in Historical Perspective"
* **New**/**Tomorrow**: Technology and the Arts:

    > Guest Artist Carol Burch-Brown is the creator of “Salt Marsh Suite” a collaborative inter-media arts installation and dance performance based in fieldwork, data collection, and close observation of a North Carolina coastal estuary. 
Join us on Thursday April 25th at 11AM in the Flanagan Theatre to see the installation, and hear Carol talk about the digital art-making processes, specifically theerror. MAX coding environment, and other digital tools she used to make this unique work. 

    > Performances: Thurs April 25-Saturday April 27 at 7:00PM and 8:30PM; Sunday April 28 2:00PMand 3:30PM.  (Need tickets)

* **Tomorrow**: McKibben lecture, Thursday, 4:15 p.m., JRC 101
* **New**: CS Table, next Tuesday, Facebook Data
* **New**: Three talks by Prof. Dr. Yvonne Foerster (<https://yvonnefoerster.com/>)
   
    > Wednesday: May 1, 4:30-6pm, HSSC S3325: _Beyond the Anthropocene: Technology, Innovation, and the (Post-)Human Condition_

    > Emergent technologies today are advertised as means to create a better future, while the futures imagined in popular science and culture move rather towards the transcendence of human life. This talk examines the conception of innovation between the technological enthusiasm to overcome human limitations and the necessity to critically reflect on the (post-)human condition.
 
    > Thursday, May 2, Noon-12:50pm, HSSC N3110 _Degrees of Freedom: Embodiment, Neuroplasticity, and the Need for a Critical Neuroscience_

    > Lunch and beverages provided
 
    > Neuroplasticity, the ability of the brain to adjust to new affordances and to overcome limitations through damage, has been part of a discourse that celebrated freedom rather than neuro-determinism. My aim is to discuss this concept with regard to the rise of neurocultures (e.g., enhancement strategies, neuromarketing) in a more critical light.
 
    > Friday, May 3, Noon-12:50pm, Bucksbaum 152: _Designing Future Bodies: Fashion and Technology_

    > Lunch and beverages provided
 
    > Fashion and technology are inextricably linked in production, marketing, design, and functionality. In this talk I shed some light on the potential of fashion to critically examine the role of technology in shaping bodies, gender, and social relations. I will take a closer look at experimental practices and scientific cooperation in the field of fashion.

#### Extra credit (Peer)

* Track and Field at Grand View on Friday.  (Go after class.)
* Music and AI, 5pm, Bucksbaum 152.
* Chamber Concert, 2pm, Saturday, Herrick

#### Extra credit (Wellness)

* **New**: Guided Movement Meditations, 12:15 Friday and Saturday,
  Flanagan Theatre.  Also between performances of the show.
* **New**: Bread-Making Workshop, Friday, 6-8 p.m.  Sign up through
  grahamj@grinnell.edu.  (Limited to 12 people.)
   
#### Extra credit (Wellness, Regular)

* 30 Minutes of Mindfulness at SHACS (SHAW) every Monday 4:15-4:45
* Any organized exercise.  (See previous eboards for a list.)
* 60 minutes of some solitary self-care activities that are unrelated to
  academics or work.  Your email reflection must explain how the activity
  contributed to your wellness.
* 60 minutes of some shared self-care activity with friends. Your email
  reflection must explain how the activity contributed to your wellness.

#### Extra credit (Misc)

### Other good things 

### Questions

_How would you write `deep-reverse`?_

> In this case, I found that the pattern for deep recursion did not
  work well, so I would use a somewhat different, but somewhat
  related strategy.

    (define deep-reverse
      (lambda (val)
        (if (list? val)
            (reverse (map deep-reverse val))
            val)))

> It works!

	> (deep-reverse 'x)
	'x
	> (deep-reverse 1)
	1
	> (deep-reverse '(a b c d e))
	'(e d c b a)
	> (deep-reverse '(a (b (c d e) f) (g (((((h i) j) k))))))
	'(((((k (j (i h))))) g) (f (e d c) b) a)

> Let's try it by hand

        (deep-reverse '(a (b (c d)) e))
        => (reverse (map deep-reverse '(a (b (c d)) e)))
        => (reverse (list (deep-reverse 'a) (deep-reverse '(b (c d))) (deep-reverse 'e)))
        => (reverse (list 'a (deep-reverse '(b (c d))) (deep-reverse 'e)))
        => (reverse (list 'a (deep-reverse '(b (c d))) 'e))
        => (reverse (list 'a (deep-reverse '(b (c d))) 'e))
        => (reverse (list 'a (reverse (map deep-reverse '(b (c d)))) 'e))
        => (reverse (list 'a (reverse (list (deep-reverse 'b) (deep-reverse '(c d)))) 'e))
        => (reverse (list 'a (reverse (list 'b (deep-reverse '(c d)))) 'e))
        => (reverse (list 'a (reverse (list 'b (reverse (map deep-reverse '(c d))))) 'e))
        => (reverse (list 'a (reverse (list 'b (reverse (list (deep-reverse 'c) (deep-reverse 'd))))) 'e))
        => (reverse (list 'a (reverse (list 'b (reverse '(c d)))) 'e))
        => (reverse (list 'a (reverse (list 'b (d c))) 'e))
        => (reverse (list 'a '((d c) b)) 'e))
        => '(e ((d c) b) a)

Analyzing algorithm efficiency
------------------------------

* We've seen that there are multiple approaches to many problems.
* How do you choose which approach to use?
    * Can I understand it?
    * Is it correct?
    * Does it use computer resources well?
        * Speed
        * Memory
* We will focus mostly on speed.
* We saw on Friday that slight difference in algorithm design can have huge impacts on the
  number of procedure calls.
* For a list of length n
     * Approximately c*n, for some constant c.
     * Approximately c*n*n
     * Approximately c*2^n

The problem of searching
------------------------

```
(define search
  (lambda (lst)
    (if (null? lst)
        "no found"
         (if (test (car lst))
             (car lst)
             (search (cdr lst))))))
```

How efficient is this?

* Hypothesis: Square of the length
* Constant time, independent of the length of the list
* Hypothesis: Directly dependent on the length because recursion is efficient
    * Claim: In the past, that's what we saw.
* Hypothesis: Not worse than these.

Issue: Do we care about whether we find it or not, and where it is in the list?

* Let's assume that it's whatever is worst.

Analysis

* Every time, we do a constant number of steps (null?, car, test, cdr, recurse) and eliminate
  one element.

Divide and conquer
------------------

Computer scientists are trained to ask "Can I do better?"

Observation: If we know that the values are in order, we can look somewhere and, depending
on what we see, discard part of the search space.

If we don't know the distribution of the values, looking in the middle is probably the
best idea.

* If I find something smaller than the thing I'm searching for (`string-ci<?`), I can throw
  away everything that comes before it.
* If I find something larger than the thing I'm seraching for, I can throw away everything
  that comes after it.

Destructive binary search (a demonstration)
-------------------------------------------

How efficient is this?  How many names will I look at if my phone book has 1000 entries?  2000?
4000?

* Start with 1000
* Throw away 500, leaving us 500 (1 observation)
* Throw away 250, leaving us 250 (2 total observations)
* Throw away 125, leaving us 125 (3 total observations)
* Throw away 62, leaving us 63 (4 total observations)
* Throw away 31, leaving us 32 (5 total observations)
* Throw away 16, leaving us 16 (6 total observations)
* Throw away 8, leaving us 8 (7 total observations)
* Throw away 4, leaving us 4 (8 total observations)
* Throw away 2, leaving us 2 (9 total observations)
* Throw away 1, leaving us 1 (10 total observations)
* Throw away 1, leaving us 0 (11 total observations)

If I start with 2000, it's only one more step.

If I start with 4000, it's one other step.

This is a lot faster than "the length of the list".  In fact, it's log_2(the length of the list).

Design issues
-------------

Lab
---

Lab writeup: 1c (Class 33)

