Chapter 1 Basic Computer Concept

23
1 Chapter 1 Basic Computer Concept 國國國國國國國國 國國國國國國國 國國國 (Chuan-Yu Chang ) 國國 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: [email protected]

description

Chapter 1 Basic Computer Concept. 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: ES 709 TEL: 05-5342601 ext. 4337 E-mail: [email protected]. Textbook. - PowerPoint PPT Presentation

Transcript of Chapter 1 Basic Computer Concept

Page 1: Chapter 1 Basic Computer Concept

1

Chapter 1Basic Computer Concept

國立雲林科技大學 資訊工程研究所張傳育 (Chuan-Yu Chang ) 博士Office: ES 709TEL: 05-5342601 ext. 4337E-mail: [email protected]

Page 2: Chapter 1 Basic Computer Concept

2

Textbook

G. Michael Schneider & Judith L. Gersting, “Invitation to Computer Science C++ Version”, 3rd Edition, 2004, ISBN:0-534-39097-8

台灣代理商:滄海書局 Tel : 04-27088787Fax : 04-27087799

Page 3: Chapter 1 Basic Computer Concept

3

A few Common Misconceptions about Computer Science

Misconception 1: Computer science is the study of computers.

Many researchers investigate problems not with actual computers but rather with formal models of computation, which are easier to study and analyze mathematically.

Misconception 2: Computer science is the study of how to write computer

programs. Programming is so primarily as a tool by which researchers

can study new ideas and build and test new solutions. Misconception 3:

Computer science is the study of the uses and applications of computers and software. The computer scientist is responsible for specifying, designing,

building, and testing software packages as well as the computer systems on which they run.

Page 4: Chapter 1 Basic Computer Concept

4

The Definition of Computer Science

The central concept in computer science is the algorithm. [Gibbs and Tucker, 1986]

Computer science is the study of algorithms, including:

1. Their formal and mathematical properties 2. Their hardware realizations 3. Their linguistic realizations 4. Their applications

Page 5: Chapter 1 Basic Computer Concept

5

The Definition of Computer Science (cont.)

Based on the definition, the tasks of the computer scientist are Study the behavior of algorithms to determine whether they

are correct and efficient. Designing and building computer systems that are able to

execute algorithms Designing programming languages and translating

algorithms into these languages so that they can be executed by the hardware.

Identifying important problems and designing correct and efficient software packages to solve these problems.

Page 6: Chapter 1 Basic Computer Concept

6

The Definition the word Algorithm

Algorithm: 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 an ordered sequence of instructions that is guaranteed to solve a specific problem. It looks like:

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

Page 7: Chapter 1 Basic Computer Concept

7

Three categories of operations

The operations used to construct algorithms can be categorized as Sequential operations :

carries out a single well-defined task, usually expressed as simple declarative sentences.

Conditional operations : “question-asking” instructions of an algorithm

Iterative operations : “looping” instructions of an algorithm.

Page 8: Chapter 1 Basic Computer Concept

8

Example:Algorithm for Programming the VCR Step1 :

If the clock calendar are not correctly set, then go to page 9 of the instruction manual and follow the instructions there before proceeding.

Step2 : Place a blank tape into the VCR tape slot.

Step3 : Repeat step 4 through 7 for each program that you

wish to record, up to maximum of 10 shows. Step4 :

Enter the channel number that you wish to record, and press the button labeled CHAN.

Page 9: Chapter 1 Basic Computer Concept

9

Algorithm for Programming the VCR (cont.)

Step5 : Enter the time that you wish recording to start, and

then press the button labeled TIME-START. Step6 :

Enter the time that you wish recording to stop, and then press the button labeled TIME-FINISH.

Step7 : This completes the programming of one show. If you

do not wish to record anything else press the button labeled END-PROG.

Step8 : Press the button labeled TIMER. Your VCR is now

ready to record.

Page 10: Chapter 1 Basic Computer Concept

10

Example:Algorithm for Adding Two m-digit Numbers Given m >=1 and two positive numbers

each containing m digits: am-1am-2 …… a0

and bm-1bm-2……b0

Wanted: cm-1cm-2…c0 where cm-1cm-2…c0 = (am-

1am-2 …… a0 )+ (bm-1bm-2……b0)

Page 11: Chapter 1 Basic Computer Concept

11

Example:Algorithm for Adding Two m-digit Numbers Step 1:

Set the value of carry to 0 Step 2:

Set the value of i equal to the value 0 Step 3:

Repeat the instructions in steps 4 through 6 until the value of i is greater than m-1 Step 4:

Add the two digits ai and bi to the current value of carry to get ci

Step 5: if ci>= 10 , reset ci to (ci -10) and reset the value of carry to 1; otherwise,

set the new value of carry to 0 Step 6:

Add 1 to i , effectively moving one column to the left

Page 12: Chapter 1 Basic Computer Concept

12

Algorithm for Adding Two m-digit Numbers (cont.)

Step 7: set cm to the value of carry

Step 8: print out the final answer, cmcm-1cm-2 … … … c0

Step 9: Stop

Page 13: Chapter 1 Basic Computer Concept

13

Analyzing the algorithm

Steps 1,2,4,6,7,8,9: sequential operations Step 5: conditional operations Step 3: iterative operations

Page 14: Chapter 1 Basic Computer Concept

14

Why formalizing the steps?

Why are formal algorithms so important in computer science ? If we can specify an algorithm to solve a problem, then we can autom

ate its solution. The machine, robot, person , or thing carrying out the steps of the alg

orithm is called a computing agent. Computer science can be viewed as “the science of algorithmic problem

solving”. Computability: is it true that every problem can be solved algorithmicall

y? Unsolvable problem To specify an algorithm, but it would take a computing agent so long to e

xecute that the solution is useless. Ex. Chessboard: brute force algorithm 假設在每一狀態有 40 個合法的移動,每盤棋約 30 步,則決定下第一步可有 40

x40x40x…x40=4030=1048

假設每秒可評估 1012步,則須花 3x1025年才能下哪一步。 We do not yet know how to solve algorithmically.

Ex. intelligence

Page 15: Chapter 1 Basic Computer Concept

15

The Formal definition of an Algorithm

The formal definition of an algorithm 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 16: Chapter 1 Basic Computer Concept

16

Examples of algorithms shampooing instructions

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

Page 17: Chapter 1 Basic Computer Concept

17

Examples of algorithms making a cherry pie

Step 1: Make the crust 1.1 Take one and one-third cups flour 1.2 Sift the flour 1.3 Mix the sifted flour with one-half cup butter an

d one-fourth cup water. 1.4 Roll into two 9-inch pie crusts.

Step 2: Make the cherry filling 2.1 Open a 16-oz can of cherry pie filling and pou

r into bowl 2.2 Add a dash of cinnamom and nutmeg, and sti

r. Step 3: Pour the filling into the crust Step 4: Bake at 350F for 45 minutes.

Page 18: Chapter 1 Basic Computer Concept

18

Unambiguous

An unambiguous operation is one that can be understood and carried out directly by the computing agent without needing to be further simplified or explained.

An operation is unambiguous , we call it a primitive operation

It is not enough for an operation to be understandable. It must also be doable by the computing agent.

Doable means there exists a computational process that allows the computing agent to complete that operation successfully. Effectively computable.

Page 19: Chapter 1 Basic Computer Concept

19

Examples of algorithms prime number

Step 1: Generate a list L of all the prime numbers: L1, L2, L3,…

Step 2: Sort the list L into ascending order. Step 3: Print out the 100th element in the

list L100. Step 4: Stop Not doable

Page 20: Chapter 1 Basic Computer Concept

20

Some examples of operations that may not be effectively computable: Write out the exact decimal value . Set average to sum/number Set the value of result to (N)1/2

Add 1 to the current value of x

Page 21: Chapter 1 Basic Computer Concept

21

…halts in a finite amount of time.

The result must be produced after the execution of a finite number of operations.

We must guarantee that the algorithm eventually reaches a statement that says “Stop, you are done”

Page 22: Chapter 1 Basic Computer Concept

22

A correct solution to the Shampooing problem (1)

Step 1: Wet your hair. Step 2: Set the value of WashCount to 0 Step 3: Repeat step 4 through 6 until the value of

WashCount equals 2. Step 4: Lather your hair Step 5: Rinse your hair Step 6: Add 1 to the value of WashCount Step 7: Stop, you have finished shampooing your

hair.

Page 23: Chapter 1 Basic Computer Concept

23

A correct solution to the Shampooing problem (2)

Step 1: Wet your hair Step 2: Lather your hair Step 3: Rinse your hair Step 4: Lather your hair Step 5: Rinse your hair Step 6: Stop, you have finished

shampooing your hair.