Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Review Session 1: Algorithms


Overview

Admin

Your Questions

Can you revisit the difference between variables and parameters?

Both variables and parameters name things/values that we use within our algorithms.

Parameters are the inputs to the algorithm.

Variables are the things we create/extract/build along the way.

In the nut butter and jelly sandwich algorithm: The things on the table were the parameters: A jar of nut butter, a jar of jam, two knives, a stack of plates, a loaf of bread, and thou.

Along the way, we built new things or otherwise identified things. We pulled out two pieces of bread. We needed a name for those slices of bread to distinguish them from the others. "The sandwich", our result.

Can you express this in terms of something more mathematical?

Let's think about adding up five numbers. Most of us only know how to add two numbers at a time.

Parameters: a, b, c, d, e.

Subroutine: Add two values, x and y

Algorithm: Add a and b. Add c to that result. Add d to that result. Add e to that result. Return the final result.

Variables: That result

Example: Add 1, 2, 3, 4, and 5. a is 1, b is 2, c is 3, d is 4, e is 5. Add 1 and 2. "That result" is 3. Add "that result" (3) and c (3), giving 6. "That result" is now 6. Add "that result" (6) and d (4), giving 10. ...

Potential ambuiguity: "That result" has different values at different times in the algorithm. Sometimes we will try to have different names for each intermediate result to avoid confusion and ambiguity. (Our variables don't vary in Scheme.)

Can you give other contexts in which we might assign parameter names?

In our almond butter and jam sandwich

Parameters: Jar 1. Jar 2. Loaf.

When making a sandwich today, Jar 1 might be "this jar of almond butter" and Jar 2 might be "this jar of blackberry jam."

The parameters are abstract, the associated values are more concrete.

Can parameters take on any value?

Some values are senseless. "Make a sandwhich using 223 and 4." "Add this jar of almond butter, this jar of jam, and this loaf of bread."

We always implicitly restrict inputs. Starting in a week or so, we will start writing notes that explicitly restrict inputs.

Can parameters change?

Between calls to an algorithm, yes. Within a particular run, we try not to change them.

Can you tell me more about a subroutine?

It's part of an algorithm. It's usually something we want to do more than once. It's also a separate algorithm.

General idea: You teach the computer (or whoever is reading your algorithm) how to do something simple, and then use that in your next algorithm.

The subroutine then becomes a building block for lots of other algorithms. (Those of you who weren't here missed the list of addition algorithms; reflect on how you teach someone to add two numbers, and what they can do once they know how to add those two numbers.)

Tell me about how you're typing these eboards

I'm using a program called vi. It's like WordPad on Windows or Textedit on a Mac, except more obscure/obtuse.

The special symbols I use let me quickly generate nicely formatted pages for your perusal.

Sample Quiz Questions

Write an algorithm that describes for a returning Grinnell student who wasn't here last semester how you now get Take-a-ways (which they will call Outtakes).

Here's an algorithm for getting ready for bed

Find a clean glass.
If you have no clean glasses, find a mug. If you have neither clean glasses nor clean mugs, do the dishes and start over. Go to sink.
Fill the glass with water. Stop when water is within 1" of rim.
Bring glass of water to bedside. Place on table