# Conclusions

My strategy for CS101 been to spend time playing with code, seeing how computers work and what they can do. Today I want to zoom out and talk about what that all means.

## Algorithm

• Concrete series of steps to accomplish a computation
• The idea of algorithm predates computers by thousands of years
--Named after ancient Baghdad astronomer and mathematician al-Khwarizmi. The word "algebra" is also derived from some of his early work ... that's a pretty influential historical figure!
• Not tied to a syntax as a computer program is
• The *idea* of the steps to perform
• e.g. long division as learned in elementary school
• No: -- I want the curb in this picture to be gray
--That's just describing the goal, not the steps to get there
• Yes: To make the curb gray, consider the average of the RGB values of each pixel. If the red value is greater than that average times 1.2 then ....
• In CS101 problems, I often write the algorithm I want done in English, letting you figure out how to express that idea in Javascript code.

## Code vs. Algorithm

• Monkey Bluescreen Algorithm - real creativity here
• -Select the blue by comparing blue to the avg
• -Pick out pixels from the back image, but at the same x/y as the front pixel
• -Copy the red/green/blue values over to the main image
• Look at the code below: it takes the creative algorithm, and breaks it down and expresses it in the simple lego-brick steps that the computer actually understands.
• That's CS101 - how a creative programmer builds something actually useful out of simple code components

Here's our monkey/moon bluescreen example code

```image = new SimpleImage("monkey.jpg");
back = new SimpleImage("moon.jpg");

for (pixel: image) {
avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
if (pixel.getBlue() > avg * 0.92) {
pixel2 = back.getPixel(pixel.getX(), pixel.getY());
pixel.setRed(pixel2.getRed());
pixel.setGreen(pixel2.getGreen());
pixel.setBlue(pixel2.getBlue());
}
}

print(image);
```

## Bug

• "Bugs" are flaws between the correct intended algorithm, and what the code actually says
• The code as written does not implement what the programmer had in mind
• The computer does not say "gosh, I don't think this is what you meant"
• The code says whatever it says, and the computer just does it
• Here is an example of code with a bug. The goal here is to change the image to grayscale.
```for (pixel: image) {
avg = pixel.getRed() + pixel.getGreen() + pixel.getBlue()/3;
pixel.setRed(avg);
pixel.setGreen(avg);
pixel.setBlue(avg);
}
```

The bug here is avg computation is missing a set of parenthesis. The intent is to do the addition, then the divide by 3. As written, only the blue value is divide by 3, the other two used as is, resulting in an avg number that is too large, like 300 or 400, so the result will be to mostly set the image to all white. The correct line for the intended algorithm is `avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;`

## How Computers Work

• Provocative claim ... Computer = Powerful + Stupid
• Now we can appreciate more nuance
• Computer systems are obviously incredibly useful .. so how is that?
• Answer: Human creativity to write code, computer dumb power - a good marriage!

## Example - Cancer Cell Grading

• How can computers be intelligent?
• Cancer cell grading research Daphne Koller of Stanford
• Show the computer many example cell slides
• Program the computer to break out many different metrics of each slide
--dark/light, dark/light of boundaries, colors, number of cells, texture, ...
• Do not pre-bias the computer about the meaning of the various metrics
• Also give the computer the survival data associated with each slide
• Let the computer recombine all the data, sift out the patterns
• "Intelligence" by looking at masses of data, guided by a human plan
• This is also basically how search engines work -- vast amounts of data (billions of web pages), run through a algorithm to figure out which pages are best for each search

## Example - Cochlear Implant

• Treatment for some forms of deafness
--Doesn't work for everyone, controversy in the deaf community
--That said, this is an amazing use of technology
• Microphone takes in sound
• Computer/electronics processes the sound into separate electrical signals
• Electrodes surgically implanted in the cochlea in the ear ... user perceives "sound"
• Researchers had the vision, the computer is just one piece
• Even from our for-loop image stuff, you can imagine a computer loop that takes in a sound signal, reconfigures it in a complex way into a series of signals for the electrodes
• deaf baby with cochlear implant hears mother's voice for the first time.
• I would be proud to work on research or technology or anything that changes people's lives like that -- wow
• I like this as a vivid example of a computer system -- marriage of the human vision of an important problem and how to solve it combined with the computer cheap/fast/available processing

## Example - Self Driving Car

• Self Driving Car
• Real time "seeing" and decision making - hard problems
• Sebastian Thru - Stanford, then Google
• Self Driving Car
• I think this is going to happen
• It saves time which everybody values
• Suppose you just kick back in your car and read while it drives
• Nick prediction: self-driving cars are going to happen in our lifetimes!

## CS101 - Generic Computer Skill

• Most people are not going to be programmers, but will use computers
• I hope CS101 has given you all an insight into logical/structured computer world, better confidence and patience to work with them
• There's a skill to using computers
• You click the button where it's supposed to do something, but it gets stuck
• Many people can't get past that moment ... what to do next?
• Through CS101 I hope you've gained some confidence and patience to read the docs and try to figure it out
• A good life skill

## After CS101 Steps

• Appreciate what they can do