Chapter 1 - An Introduction to Computer Science

(1.1) What is computer science?

These three views of computer science are not necessarily wrong; they are just incomplete.

(1.2) The Definition of Computer Science

According to N. E. Gibbs and A. B. Tucker, computer science is the study of algorithms, including:

  1. their formal and mathematical properties (are they correct and efficient;)

  2. their hardware realizations (building computer systems that can execute them;)

  3. their linguistic realizations (designing programming languages and translating the algorithms into these languages;) and

  4. their applications (using them in software packages to solve important problems.)

A dictionary definition of the word algorithm:

n. A procedure for solving a mathematical problem in a finite number of steps that frequently involves repetition of an operation; broadly: a step-by-step method for accomplishing some task.

An algorithm is a list that looks something like this:

Step 1 Do something
Step 2 Do something
Step 3 Do something
.
.
.
Step N Stop, you are finished

There are three different types of operations in an algorithm:

  1. A sequential operation carries out a single well-defined task and then the algorithm moves on to the next operation. Examples:

  2. A conditional operation asks a question and then selects the next operation to be executed based on the answer to that question. Examples:

  3. An iterative operation tells us to repeat a block of operations. Examples:

Figure 1.1 in the text shows an 8-step algorithm for programming a VCR.

Figure 1.2 in the text shows a formal algorithm for adding two m-digit numbers.

Exercise 7 of Chapter 1 on page 34 of the text shows Euclid's algorithm for finding the greatest common divisor (GCD) of two positive integers I and J.


EUCLID'S ALGORITHM
StepOperation
1Get two positive integers as input. Call the larger value I and the smaller value J.
2Divide I by J (using the long division algorithm you learned in grade school) to get an integer quotient Q and an integer remainder R.
3If R is not 0, then reset the value of I to the value of J, reset the value of J to the value of R, and go back to Step 2.
4Otherwise the value of R = 0, so print out the value of J as the answer (the GCD of the original values of I and J.)
5Stop.

Why are formal algorithms so important in computer science?

If we can formally specify an algorithm to solve a problem, then we can automate its solution. That is, we can:

The machine, robot, person, or thing carrying out the steps of the algorithm is called a computing agent.

Much of the R&D work in computer science involves discovering correct and efficient algorithms for a wide variety of interesting problems.

Does every problem have an algorithmic solution?

Chapter 11 in the text shows some problems that have no algorithmic solutions. These problems are unsolvable. There's a limit on the ultimate capability of computers.

There are also problems with algorithmic solutions but the algorithms would take so long to execute as to render them useless. For example, one could write an algorithm to always win at the game of chess but it would take more than 1028 years to execute.

There are also problems that humans (even babies) can rapidly solve but do not as yet have efficient algorithmic solutions.

(1.3) Algorithms

The formal definition of an algorithm:

Let's examine this definition phrase-by-phrase:

... a well-ordered collection ...

An algorithm is a collection of operations, and there must be a clear and unambiguous ordering to these operations: we must know which operation to do first and after each operation we must know which operation to do next.

As an example the text shows an "algorithm" taken from the back of a shampoo bottle:

Step 1:Wet hair
Step 2:Lather
Step 3:Rinse
Step 4:Repeat

Is this a well-ordered set of operations? At step 4 what operations should be repeated?

A well-ordered set of operations can't have ambiguous statements like:

... of unambiguous and effectively computable operations ...

The computing agent must be able to understand each and every step of the algorithm. As an example the text shows a possible "algorithm" for making a cherry pie:

Step 1:Make the crust
Step 2:Make the cherry filling
Step 3:Pour the filling into the crust
Step 4:Bake at 350oF for 45 minutes

Steps 3 and 4 are pretty clear but most of us might need detailed instructions for steps 1 and 2:

Step 1:Make the crust
1.1:Take one and a third cups of flour
1.2:Sift the flour
1.3:Mix the sifted flour with one-half cup butter and one-fourth cup water
1.4:Roll into two 9-inch pie crusts
Step 2:Make the cherry filling
2.1:Open a 16-ounce can of cherry pie filling and pour into bowl
2.2:Add a dash of cinnamon and nutmeg, and stir

The "computing agent" might not understand how to sift the flour in step 1.2 and would need even more detail:

Step1.2:Sift the flour
1.2.1:Get out the sifter, which is the device shown on page A-9 of your cookbook, and place it directly on top of a two-quart bowl
1.2.2: Pour the flour into the top of the sifter and turn the crank counterclockwise
1.2.3: Let all the flour fall through the sifter into the bowl

An unambiguous operation is so simple that the computing agent can understand and perform it: we call it a primitive operation or simply a primitive.

Each operation must also be effectively computable. Flapping one's arms until you start to fly or generating a list of all prime numbers are not effectively computable.

... that produces a result ...

We say result instead of answer because sometimes there is no correct answer. The result of an algorithm could be an error message instead of a correct answer.

... and halts in a finite amount of time.

The shampooing "algorithm" has an infinite loop.

(1.4) A Brief History of Computing

(1.4.1) The Early Period: Up to 1940. The first computers used ideas that were developed over hundreds of years by many people:

(1.4.2) The Birth of Computers: 1940-1950 (1.4.3) The modern era: 1950 to the Present. The major advancements in computing since 1950 are summarized in Fig. 1.8 in the text.

(1.5) Organization of the Text

The rest of the course and the text is organized into a six-layer hierarchy as depicted in Fig. 1.9 of the text.


Kenneth E. Batcher - 8/27/2006