# Class 02: Introduction to the Course

Back to Algorithms: Thinking Formally. On to HTML: A Formal Markup Language.

Held Monday, September 2, 2002

Summary

Today, we continue our introduction to the course by discussing the purpose, format, and policies of the course. We also reflect on our activities from the previous class.

Notes

• Some of you had problems submitting your surveys. I'm sorry about that problem. (I made one small change and didn't check to ensure that things still worked afterwards.)
• No, I haven't had a chance to read through them yet.

Due

Assignments

Overview

• Generalizing: What techniques did we use for PBJ?
• Course basics

## The Parts of an Algorithm

• As you may have noted, there are some common aspects to algorithms. That is, there are techniques that we use in many of the algorithms we write.
• It is worthwhile to think about these algorithm parts because we can rely on them when we write new algorithms.

### Variables: Named Values

• As we write algorithms, we like to name things.
• Sometimes we use long names, such as the piece of bread in your left hand.
• Sometimes, we use shorter names, such as bread-left.
• As we start to write more formal algorithms, we will need techniques for declaring names and indicating what they name.
• We call these named values variables, even though they don't always vary.

### Parameters: Named Inputs

• Many algorithms take data as input (and generate other data as output).
• Our PBJ algorithm takes bread, jelly, and such as input.
• A find square root algorithm would take a number as input.
• A look up a telephone number algorithm might take a phone book and a name to lok for as inputs.
• In each case, the algorithm should works on many different inputs.
• The algorithm works as long as the input is reasonable (we can't find the square root of a piece of bread and we can't make a PBJ sandwich with tunafish).
• We call these inputs parameters.

### Conditionals: Handling Different Conditions

• At times, our algorithms have to account for different conditions, doing different things depending on those conditions.
• In our PBJ algorithm, we might check whether the jar of peanut butter is open or what kind of lid is on the jelly jar. We call such operations conditionals.
• Conditionals typically take either the form
if some condition holds then do something
• Here's a slightly more complex form
if some condition holds then do something otherwise do something else
• At times, we need to decide between more than two possibilities. Typically, we organize those as a sequence of tests (called guards) and corresponding things to do.

### Repetition

• At times, our algorithms require us to do something again and again.
• In our PBJ algorithm, we may have had to turn the twisty-tie again and again until it was untwisted.
• We call this technique repetition.
• Again, repetition takes many forms.
• We might do work until we've reached a desired state.
• We might continue work as long as we're in some state.
• We might repeat an action a fixed number of times.
• You can probably think of many other forms of repetition.

### Subroutines: Named Helper Algorithms

• Many algorithms require common actions for their operation.
• For example, to make N sandwiches, you benefit from knowing how to make one sandwich.
• To make a peanut butter and jelly sandwich, it helps to know how to spread something on bread.
• We can write additional algorithms for these common actions and use them as part of our broader algorithm.
• We can also use them in other algorithms.
• We call these helper algorithms subroutines.

• I expect and hope that you will find CSC151 different from any class you've taken in the past.
• We use a different format than many classes: a collaborative, workshop-style format. (You may have seen this format in other introductory science courses; we do it somewhat differently.)
• Computers and computer science also require you to think differently. I expect that you'll exercise some brain cells you may have forgotten you have. (And after all, isn't liberal arts education an exercise in thinking in as many ways as you can?)
• Computer Science 151 has a number of goals
• To introduce you to fundamental ideas of computer science: abstraction, algorithms, and data
• To enhance your problem-solving skills and give you experience in formal representation of problems and solutions.
• To introduce you to two primary paradigms of problem solving: functional and imperative.
• To give you some programming skills that you can apply to problems in other disciplines.
• Like most computer science courses, CSC151 will have both theoretical and practical components. I hope you will enjoy relating the two.

• You may have noted that I said that we'll study two paradigms of problem solving.
• Over the years, computer scientists have designed (discovered?) a number of techniques for looking at how to write solutions to problems. There are four basic ones.
• We'll visit each in terms of making cookies (or at least we'll try).
• Imperative: Solutions are a collection of basic instructions with some additional sequencing.
• Sift dry ingredients.
• Stir 50 times.
• ...
• Object-Oriented: Solutions are a collection of interacting objects.
• Head chef: Hand bowl of ingredients to mixing sous-chef.
• Sous-chef: Upon receiving bowl of ingredients, mix.
• ...
• Functional: Solutions consist of function definitions and function applications. It's often useful to think of a function as a form of filter: it converts its input to output.
• The mixer converts separate ingredients into a consistent mush.
• The oven converts raw dough to cooked dough.
• Declarative: Solutions consists of collections of facts.
• To bake cookies, you cook at 375 degrees F for 8 to 10 minutes.
• Chocolate chip cookies contain ...

## The Need for Formality

• Some people wonder why we need computer languages like Scheme, Pascal, C, Java, and the ilk.
• In part, it's probably because the computer elite want to maintain their sense of superiority over the masses.
• In greater part, it's because English and other natural languages can be ambiguous. At the very least, they have many similar structures that are interpreted very differently. Consider the classic pair of
• Time flies like an arrow.
• Fruit flies like a banana.
• Remember: Computers are sentient and malicious. It often seems that they'll do their best to misinterpret whatever it is you write.

• Please refer to the course web site for more details.
• Teaching philosophy: I support your learning.
• Policies
• Attendance: I expect you to attend every class. Let me know when you'll miss class and why.
• Course web.
• ECA. We'll use it for turning in homework and quizzes.
• Etc.
• Daily work
• Attend class, work on lab and participate in discussion.
• Finish the lab in the evening.
• Do the reading for the next class in the evening.
• The exams
• Three take-home exams during the semester. Plan to spend ten hours on each one.
• An optional final to make up for a bad exam grade.
• Take all three exams anyway.
• The labs
• Available online.
• Being re-written as the semester progresses.
• I'll require more formal writeups of a few labs a semester.
• The homework
• One makeup at the end of the semester.
• The project
• After break.
• Ties together many ideas.
• Core to the academic process.
• My basic policy: Don't cheat.
• The college's basic policy: Cite carefully.
• Significant breakdowns in CSC151 last semester.

## Why Scheme?

• Some of you have asked (explicitly or implicitly) why we use Scheme in 151, rather than a practical language, like C or Java.
• Because we believe in a multi-paradigm introduction, we want a language that supports more than one paradigm. Scheme supports imperative and functional programming (and a form of object-oriented programming).
• Our experience shows that too much of intro courses is typically spent on the grammar of programming languages (how to put sentences together). Scheme has a simple and consistent grammar.
• Scheme also lets us avoid some other issues that don't contribute to your learning.
• Scheme provides an elegant and appropriate introduction to recursion, a key problem-solving concept. We find that Scheme students learn recursion more quickly and better.
• Scheme is sometimes the language of choice for embedded languages. You can program a text editor (emacs) and a sophisticated graphics program (GIMP) using Scheme.
• We'll investigate GIMP this semester.
• Anything you can do in any other language, you can do in Scheme.
• We're in good company. MIT, the University of Chicago, Rice, The University of Texas at Austin, Berkeley, Swarthmore, and a number of other top institutions use Scheme as the first language (or have done so in the recent past).

## History

Thursday, 29 August 2002

Friday, 30 August 2002

Monday, 2 September 2002

• Added section on the parts of an algorithm, taken from the previous outline.
• Moved Getting Started in the MathLAN to the next outline.

Back to Algorithms: Thinking Formally. On to HTML: A Formal Markup Language.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Mon Dec 2 08:40:45 2002.
The source to the document was last modified on Mon Sep 2 08:02:56 2002.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Outlines/outline.02.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu