Download presentation
Presentation is loading. Please wait.
Published byDebra Wade Modified over 9 years ago
1
1 Chapter 1 Basic Computer Concept 國立雲林科技大學 資訊工程研究所 張傳育 (Chuan-Yu Chang ) 博士 Office: EB 212 TEL: 05-5342601 ext. 4337 E-mail: chuanyu@yuntech.edu.twchuanyu@yuntech.edu.tw Http://MIPL.yuntech.edu.tw
2
2 Textbook G. Michael Schneider & Judith L. Gersting, “ Invitation to Computer Science C++ Version ”, 3rd Edition, 2004, ISBN:0-534-39097-8 台灣代理商:滄海書局 Tel : 04-27088787 Fax : 04-27087799
3
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.
4
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
5
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.
6
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 something Step 2 Do something Step 3 Do something : : Step N Stop, you are finished
7
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.
8
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.
9
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.
10
10 Example: Algorithm for Adding Two m-digit Numbers Given m >=1 and two positive numbers each containing m digits: a m-1 a m-2 …… a 0 and b m-1 b m-2 ……b 0 Wanted: c m-1 c m-2 …c 0 where c m-1 c m-2 …c 0 = (a m-1 a m-2 …… a 0 )+ (b m-1 b m-2 ……b 0 )
11
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 a i and b i to the current value of carry to get c i Step 5: if c i >= 10, reset c i to (c i -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
12
12 Algorithm for Adding Two m-digit Numbers (cont.) Step 7: set c m to the value of carry Step 8: print out the final answer, c m c m-1 c m-2 … … … c 0 Step 9: Stop
13
13 Analyzing the algorithm Steps 1,2,4,6,7,8,9: sequential operations Step 5: conditional operations Step 3: iterative operations
14
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 automate its solution. The machine, robot, person, or thing carrying out the steps of the algorithm 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 algorithmically? Unsolvable problem To specify an algorithm, but it would take a computing agent so long to execute that the solution is useless. Ex. Chessboard: brute force algorithm 假設在每一狀態有 40 個合法的移動,每盤棋約 30 步,則決定下第一步可有 40x40x40x…x40=40 30 =10 48 假設每秒可評估 10 12 步,則須花 3x10 25 年才能下哪一步。 We do not yet know how to solve algorithmically. Ex. intelligence
15
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.
16
16 Examples of algorithms shampooing instructions Step 1Wet hair Step 2Lather Step 3Rinse Step 4Repeat
17
17 Examples of algorithms making a cherry pie Step 1:Make the crust 1.1Take one and one-third cups flour 1.2Sift the flour 1.3Mix the sifted flour with one-half cup butter and one- fourth cup water. 1.4Roll into two 9-inch pie crusts. Step 2:Make the cherry filling 2.1Open a 16-oz can of cherry pie filling and pour into bowl 2.2Add a dash of cinnamom and nutmeg, and stir. Step 3:Pour the filling into the crust Step 4:Bake at 350F for 45 minutes.
18
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.
19
19 Examples of algorithms prime number Step 1: Generate a list L of all the prime numbers: L 1, L 2, L 3,… Step 2: Sort the list L into ascending order. Step 3:Print out the 100th element in the list L 100. Step 4:Stop Not doable
20
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
21
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”
22
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.
23
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.