16
1 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 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)

Embed Size (px)

Citation preview

Page 1: 1 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

CS1000Introduction to Computer

Science

InstructorSoufiane Noureddine

LecturesTu/Th: 12:15-13:30 (B650)

Office HoursTu/Th: 11:00-12:00 (C520)

Page 2: 1 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)

2

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.)

Page 3: 1 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)

3

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.

Page 4: 1 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)

4

What Computer Science Is Not CS = Study of computer applications

and software? Application: e.g. spreadsheets, word

processors, databases … Comparison:

Mechanical Engineer Computer ScientistConceives a car conceives computer/softwareBuilds and tests it builds and tests it

UserGets a driver license Gets some certificateDrives the car Exploits the

computer/software

Page 5: 1 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)

5

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

Page 6: 1 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)

6

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

Page 7: 1 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)

7

Simple Example for an algorithm “Breakfast”

1. Get a slice of bread 2. Butter it 3. Eat the buttered slice 4. If still hungry then resume from

step 1, otherwise drink a cup of tea and stop.

Page 8: 1 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)

8

Other examples for algorithms

Backing a pie Using the telephone set Programming the VCR Doing tax calculation …

Page 9: 1 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)

9

Summing up the first n integers 1 + 2 + 3 + … + n ? Algorithm

1. Get the number n 2. Set m to n+1 3. Set n to n multiplied by m 4. Divide n by 2 5. Display the result n

Page 10: 1 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)

10

The Concept of Algorithm Inventor: Abu Jaafar Mohammed Ibn-Musa Al-

Khawarizmi 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.

Page 11: 1 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)

11

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.

Page 12: 1 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)

12

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!

Page 13: 1 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)

13

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

Page 14: 1 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)

14

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

Page 15: 1 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)

15

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

That produces a result Any algorithm should produce a result observable to

the end user. Result may be:

Answer Error message …

Page 16: 1 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)

16

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. Get a slice of bread 2. Butter it 3. Eat the buttered slice 4. Repeat from step 1 5. Drink a cup of tea 6. Stop

Common flaw in the design of algorithms: Endless loops

The Concept of Algorithm