Transcript chp01

CS1000
Introduction to Computer Science
Instructor
Soufiane Noureddine
Lectures
Tu/Th: 12:15-13:30 (B650)
Office Hours
Tu/Th: 11:00-12:00 (C520)
1
What Computer Science Is Not

Computer Science (CS) = Study of
Computers?



CS began earlier than computers (branch
of math)
Theoretical CS (pencil and paper)
Computer is only the basic tool in CS (e.g.
beaker for chemistry, microscope for
biology etc.)
2
What Computer Science Is Not

CS = Study of how to write programs?



Use of programming languages e.g. Pascal, Lisp,
C, etc.
Very important but also only a tool in CS for
verifying ideas and concepts after their analysis.
Example: “Searching in a list”




Analyze the problem
Design a searching method
Write a program
Get quantitative and qualitative results.
3
What Computer Science Is Not

CS = Study of computer applications and
software?


Application: e.g. spreadsheets, word processors,
databases …
Comparison:

Mechanical Engineer
Conceives a car
Builds and tests it

Computer Scientist
conceives computer/software
builds and tests it
User
Gets a driver license
Drives the car
Gets some certificate
Exploits the computer/software
4
Definition of CS


No real consensus (yet).
A good definition that emphasizes the
notion of “algorithm” is:

CS is the study of algorithms including
their:




Formal and mathematical properties
Hardware realizations
Linguistic realizations
Applications
5
Algorithm

Informally: Effective and precise recipe
to get the result for some problem:



“Recipe”: Set of commands/instructions
“Effective”: The result is obtainable after
some time
“Precise”: exactness, only understandable
and doable commands
6
Simple Example for an
algorithm

“Breakfast”




1.
2.
3.
4.
Get a slice of bread
Butter it
Eat the buttered slice
If still hungry then resume from step 1,
otherwise drink a cup of tea and stop.
7
Other examples for algorithms





Backing a pie
Using the telephone set
Programming the VCR
Doing tax calculation
…
8
Summing up the first n
integers


1+2+3+…+n?
Algorithm





1.
2.
3.
4.
5.
Get the number n
Set m to n+1
Set n to n multiplied by m
Divide n by 2
Display the result n
9
The Concept of Algorithm

Inventor: Abu Jaafar Mohammed Ibn-Musa AlKhawarizmi




Arabic mathematician of the 8th century
Born in Khawarizm (Persia)
Lived in Baghdad where he worked in Beitu Alhikma
(House of Wisdom) under the Khalif Al-Maamoon.
Wrote two famous books:


One is a treatise on the calculation using Arabic numerals,
his name was translated in Latin to Algorismus, from there
the word algorithm.
The other is even more famous since it introduced
“algebra” as a new fundamental branch of mathematics.
The book is Kitab Aljabr Wal Muqabala (Book of
Restoration and Reduction) -> Aljabr had been translated
to Algebra.
10
The Concept of Algorithm


The main benefit of algorithms is that we
can automate the solution for every
problem we can find an algorithm for
solving it.
Formal definition of an algorithm:

An algorithm is a well-ordered collection of
unambiguous and effectively computable
operations that when executed produces a
result and halts in a finite amount of time.
11
The Concept of Algorithm

Well-ordered collection


We have to always know what to do next.
Counterexample:




1. Get a slice of bread
2. Butter it
3. Eat buttered slice
4. Repeat
-> 4th step: repeat what?
-> not an algorithm!
12
The Concept of Algorithm

Unambiguous + effectively computable operations


Operations: units of work the computer can do.
Different levels of operations are possible:




Example: “Breakfast”
 1. Eat buttered bread until “full”
 2. Drink a cup of tea
 3. Stop
-> Step 1 may be too “high” for a kid
Step 1 is a sequence of (sub-)operations, it also forms an
algorithm!
Possible algorithm for Step 1:
 1. Get a slice of bread
 2. Butter it
 3. Eat the buttered slice
 4. If still hungry resume from 1
13
The Concept of Algorithm

Operations should be unambiguous




directly doable
need not be further explained (e.g. using sub-operations)
Unambiguous operations are also called primitives
Any operation must be doable


Unambiguous (understandable) but not doable operations
are not welcome for algorithms
Hence only effectively computable operations should be
used
14
The Concept of Algorithm

Examples of unambiguous but not effectively computable
operations:





List all positive numbers
Divide by 0
Compute for ever
Print the exact value of p
That produces a result


Any algorithm should produce a result observable to the end
user.
Result may be:



Answer
Error message
…
15
The Concept of Algorithm

And halts in a finite amount of time



Practically one of the most crucial properties of algorithms
Algorithms that work well but cannot stop are useless
Example: “Endless Loop”







1.
2.
3.
4.
5.
6.
Get a slice of bread
Butter it
Eat the buttered slice
Repeat from step 1
Drink a cup of tea
Stop
Common flaw in the design of algorithms: Endless loops
16