1 / 76

Chapter 1: An Introduction to Computer Science

Invitation to Computer Science, C Version, Fourth Edition. 2. Objectives. In this chapter, you will learn aboutThe definition of computer scienceAlgorithms. Invitation to Computer Science, C Version, Fourth Edition. 3. Introduction. Common misconceptions about computer scienceComputer science

kerri
Download Presentation

Chapter 1: An Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Chapter 1: An Introduction to Computer Science Invitation to Computer Science, Java Version, Third Edition

    2. Invitation to Computer Science, C++ Version, Fourth Edition 2 Objectives In this chapter, you will learn about The definition of computer science Algorithms

    3. Invitation to Computer Science, C++ Version, Fourth Edition 3 Introduction Common misconceptions about computer science Computer science is the study of computers Computer science is the study of how to write computer programs Computer science is the study of the uses and applications of computers and software

    4. Invitation to Computer Science, C++ Version, Fourth Edition 4 The Definition of Computer Science Gibbs and Tucker definition of computer science Computer science is the study of algorithms that is used to solve problems. The problem solving process involves 4 steps: Creating correct and efficient algorithms Building computers to execute algorithms Designing programming languages to translate algorithms Applications

    5. Invitation to Computer Science, C++ Version, Fourth Edition 5 Quiz 1. (T/F) Computer science is the study of allergy. 2. (T/F) Building cars is one of problems solving steps used by computer scientists. 3. (T/F) Designing programming languages is the third step of problems solving steps used by computer scientists.

    6. Invitation to Computer Science, C++ Version, Fourth Edition 6 The Definition of Computer Science (continued) Algorithm An ordered step by step instructions that is guaranteed to solve a specific problem

    7. Invitation to Computer Science, C++ Version, Fourth Edition 7 The Definition of Computer Science (continued) An algorithm is a list that looks like STEP 1: Do something. STEP 2: Do something. STEP 3: Do something. . . . . . . STEP N: Stop. You are finished.

    8. Invitation to Computer Science, C++ Version, Fourth Edition 8 Example of Algorithm: How to make sticky rice? 1. Measure Your Sticky Rice. 2. Add Water and Let Soak. 3. Add Salt and Bring to a Boil. 4. Cook the Rice. 5. Use a Fork to Check the Rice. 6. Allow Rice to Steam-Cook for 20 min.. 7. Enjoy Your Sticky Rice!

    9. Invitation to Computer Science, C++ Version, Fourth Edition 9 Criteria for Correct Algorithm Criteria 1. unambiguous instructions 2. computable instructions 3. producing results 4. stopping in a finite amount of time Example: 1. Add X to some numbers ->violate criteria 1 2. Set X to (5 / 0) ->violate criteria 2 and 3 3. Repeat Step 4 Until X > 10 ->violate criteria 4 4. Set X = 1 5. Stop

    10. Invitation to Computer Science, C++ Version, Fourth Edition 10 Algorithm Operation 1: Sequential Operation Sequential operations Carry out a single well-defined task; when that task is finished, the algorithm moves on to the next operation Examples: 1. Set X to 1 2. Set Y to 2 3. Set Z to X + Y 4. Print Z 5. Stop

    11. Invitation to Computer Science, C++ Version, Fourth Edition 11 Quiz What is the output of Step 4 of the following algorithm? 1. Set Y to 4 2. Set W to 2 3. Set P to (Y + W) / 2 4. Print P 5. Stop

    12. Invitation to Computer Science, C++ Version, Fourth Edition 12 Quiz What is the output of Step 4 of the following algorithm? 1. Set Y to 4 2. Set W to Y + 2 3. Set Y to (Y + W) / 2 4. Print Y 5. Stop

    13. Invitation to Computer Science, C++ Version, Fourth Edition 13 Algorithm Operation 1: Conditional Operation Conditional operations Ask a question and then select the next operation to be executed on the basis of the answer to that question Examples 1. Set X to 1 2. If X is even then Set Y to 1 else Set Y to 2 3. Stop

    14. Invitation to Computer Science, C++ Version, Fourth Edition 14 Quiz What is the output of Step 3 of the following algorithm? 1. Set X to 4 2. If X > 3 then Set Y to ‘A’ else Set Y to ‘B’ 3. Print Y 4. Stop

    15. Invitation to Computer Science, C++ Version, Fourth Edition 15 The Definition of Computer Science (continued) Iterative operations Go back and repeat the execution of a previous block of instructions Examples 1. Set X to 1 2. Repeat Step3 Until X is 3 3. Set X to X + 1 4. Stop

    16. Invitation to Computer Science, C++ Version, Fourth Edition 16 Quiz What is the output of Step 3 of the following algorithm? 1. Set X to 1 2. Set Y to 2 3. Repeat Step4-5 Until X is 3 4. Set X to X + 1 5. Set Y to Y + 2 6. Stop

    17. Invitation to Computer Science, C++ Version, Fourth Edition 17 What is the output of Step 6 of the following algorithm?_____ How many times have step 4 been executed? ____ 1. Set X to 1 2. Set Y to 2 3. Repeat Step4-5 Until X is Y > 7 4. Set X to X + 3 5. Set Y to Y + 3 6. Print Y 7. Stop

    18. Invitation to Computer Science, C++ Version, Fourth Edition 18 Quiz What is the output of Step 6 of the following algorithm?_____ How many times have step 4 been executed? ____ 1. Set X to 1 2. Set Y to 2 3. Repeat Step4-5 Until X is Y > 7 4. Set X to X + 3 5. Set Y to Y + 3 6. Print X 7. Stop

    19. Invitation to Computer Science, C++ Version, Fourth Edition 19 What is boolean? a boolean is either TRUE or FALSE What is the output of the following algorithm?___ 1. Set B to FALSE 2. If B is TRUE then Set A to ‘OK’ else Set A to ‘YES’ 3. Print A 4. Stop

    20. Invitation to Computer Science, C++ Version, Fourth Edition 20 Quiz What is the output of step 4 of the following algorithm?___ Has the statement ‘Set A to TRUE’ been executed? _____ 1. Set B to TRUE 2. If B is TRUE then Set A to FALSE Else Set A to TRUE 3. If A is FALSE then Set W to ‘X’ Else Set W to ‘Y’ 4. Print W 5. Stop

    21. Invitation to Computer Science, C++ Version, Fourth Edition 21

    22. Invitation to Computer Science, C++ Version, Fourth Edition 22 Quiz What is the output on step 6? ________ How many times of step 4 been executed? _______ 1. Set INDEX to 1 2. Set DONE to false 3. Repeat steps 4-5 until DONE is true 4. Set INDEX to INDEX + 2 5. If INDEX > 5 then Set DONE to true 6. Print INDEX 7. Stop

    23. Invitation to Computer Science, C++ Version, Fourth Edition 23 Repeat/Until Repeat A Until B meaning if B is not true then do A.

    24. Invitation to Computer Science, C++ Version, Fourth Edition 24 While /Do While A Do B meaning if A is true then do B

    25. Invitation to Computer Science, C++ Version, Fourth Edition 25 What is the output of step 6?_____ How many times have step5 been executed? ____ 1. Set INDEX to 1 2. Set SUM to 1 3. While INDEX <= 5 do steps 4 - 5 4. Set SUM to SUM + INDEX 5. Set INDEX to INDEX + 2 6. Print SUM 7. Stop

    26. Invitation to Computer Science, C++ Version, Fourth Edition 26 Quiz What is the output of step 6?_____ How many times have step5 been executed? ____ 1. Set INDEX to 2 2. Set SUM to 3 3. While INDEX <= 8 do steps 4 - 5 4. Set SUM to SUM + INDEX 5. Set INDEX to INDEX + 3 6. Print SUM 7. Stop

    27. Invitation to Computer Science, C++ Version, Fourth Edition 27 What is the output of step 8?_____ How many times have step5 been executed? ____ 1. Set INDEX to 1 2. Set SUM to 1 3. Set DONE to false 4. While DONE is false do steps 5-7 5. Set SUM to SUM + INDEX 6. Set INDEX to INDEX + 3 7. If INDEX > 7 THEN Set DONE to true 8. Print SUM 9. Stop

    28. Invitation to Computer Science, C++ Version, Fourth Edition 28 Quiz What is the output of step 8?_____ How many times have step5 been executed? ____ 1. Set INDEX to 1 2. Set SUM to 1 3. Set DONE to false 4. While DONE is false do steps 5-7 5. Set SUM to SUM + INDEX 6. Set INDEX to INDEX + 3 7. If INDEX > 7 THEN Set DONE to true 8. Print SUM 9. Stop

    29. Invitation to Computer Science, C++ Version, Fourth Edition 29 Quiz - Challenge What is the output on step 6? ________ How many times of step 4 been executed? _______ 1. Set INDEX to 0 2. Set DONE to true 3. Repeat steps 4-5 until DONE is true 4. Set INDEX to INDEX + 1 5. If INDEX > 2 then Set DONE to true 6. Print INDEX 7. Stop

    30. Invitation to Computer Science, C++ Version, Fourth Edition 30 Quiz What is the output of step 8?_____ How many times have step5 been executed? ____ 1. Set INDEX to 1 2. Set SUM to 1 3. Set DONE to true 4. While DONE is false do steps 5-7 5. Set SUM to SUM + INDEX 6. Set INDEX to INDEX + 3 7. If INDEX > 7 THEN Set DONE to true 8. Print SUM 9. Stop

    31. Invitation to Computer Science, C++ Version, Fourth Edition 31 Chapter 1. Exercises Samples Exercise 5. Under what conditions would the following function not be effectively computable? F(x) = sqrt(a)/b

    32. Invitation to Computer Science, C++ Version, Fourth Edition 32 Chapter 1. Exercises Samples Exercise 7. What is the output of the following algorithm if X is 5 and Y is 2? 1. Get X 2. Get Y 3. Divide X by Y and call the reminder R 4. If R is not 0 then reset X to X-1 and go back to step 3. 5. Print X 6. Stop

    33. Invitation to Computer Science, C++ Version, Fourth Edition 33 Exercise 9 Samples Write an algorithm to compute the area of a rectangle. Area = Length * Width Get Length Get Width Set Area = Length * Width Print Area Stop

    34. Invitation to Computer Science, C++ Version, Fourth Edition 34 Quiz Write an algorithm to compute the area of a triangle. Rule: Area = Height * Width / 2

    35. Invitation to Computer Science, C++ Version, Fourth Edition 35 Exercise 9 Sample. Write an algorithm to determine the financial status. Rule: If the savings > $10000 then output ‘Good’ otherwise ‘Bad’. Get Savings If Savings > $10000 Set Status = “Good” Else Set Status = “Bad” Print Status Stop

    36. Invitation to Computer Science, C++ Version, Fourth Edition 36 Quiz Write an algorithm to determine the weather status. Rule: If the temperature < 32F then output ‘Cold’ otherwise ‘Warm’.

    37. Invitation to Computer Science, C++ Version, Fourth Edition 37 Quiz Write an algorithm to compute the following mysterious equation. Be sure to print the error message when C is 0. rule: A = B / C

    38. Invitation to Computer Science, C++ Version, Fourth Edition 38 Example. If/else Write an algorithm to compute and display the value sqrt(x) if the value of x is not negative. If x is negative, then display the message ‘Unable to perform the sqrt() operation.’ 1. Get X 2. If X < 0 Print “Unable to perform the sqrt()” Else Print sqrt(x) 3. Stop

    39. Invitation to Computer Science, C++ Version, Fourth Edition 39 Quiz Write an algorithm to compute and display the value a/b if the value of b is not 0. If b is 0, then display the message ‘Unable to perform the division.’

    40. Invitation to Computer Science, C++ Version, Fourth Edition 40 Loop Exercise 1. The worst solution. Write an algorithm to compute Sum = 2+3+4? 1. Set Sum to 0 2. Set Num to 2 3. Set Sum = Sum + Num 4. Set Num to Num + 1 5. Set Sum = Sum + Num 6. Set Num to Num + 1 7. Set Sum = Sum + Num 8. Print Sum 9. Stop

    41. Invitation to Computer Science, C++ Version, Fourth Edition 41 Loop Exercise 2. The best solution Write an algorithm to compute Sum = 2+3+4?

    42. Invitation to Computer Science, C++ Version, Fourth Edition 42 Loop Exercise 2. The best solution Write an algorithm to compute Sum = 2+3+4?

    43. Invitation to Computer Science, C++ Version, Fourth Edition 43 Quiz. Loop. Use While/Do to write an algorithm to compute sum = 1 + 2 + 3 + 4+ 5 + 6 + 7 + 8 + 9 + 10

    44. Invitation to Computer Science, C++ Version, Fourth Edition 44 Quiz. Loop. Use Repeat/Until to write an algorithm to compute sum = 1 + 2 + 3 + 4+ 5 + 6 + 7 + 8 + 9 + 10

    45. Invitation to Computer Science, C++ Version, Fourth Edition 45 Use While/Do to write an algorithm to compute sum = 2 + 4 + 6 + 8 + 10

    46. Invitation to Computer Science, C++ Version, Fourth Edition 46 The Definition of Computer Science (continued) Iterative operations Tell us to go back and repeat the execution of a previous block of instructions Examples Repeat the previous two operations until the mixture has thickened While there are still more checks to be processed, do the following five steps Repeat steps 1, 2, and 3 until the value of y is equal to 11

    47. Invitation to Computer Science, C++ Version, Fourth Edition 47 The Definition of Computer Science (continued) If we can specify an algorithm to solve a problem, we can automate its solution Computing agent: The machine, robot, person, or thing carrying out the steps of the algorithm Does not need to understand the concepts or ideas underlying the solution

    48. Invitation to Computer Science, C++ Version, Fourth Edition 48 The Formal Definition of an Algorithm 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 Unambiguous operation An operation that can be understood and carried out directly by the computing agent without needing to be further simplified or explained Ambiguous example, ‘Set X to some number’

    49. Invitation to Computer Science, C++ Version, Fourth Edition 49 The Formal Definition of an Algorithm (continued) A primitive operation (or a primitive) of the computing agent Operation that is unambiguous for computing agent Primitive operations of different individuals (or machines) vary An algorithm must be composed entirely of primitives Effectively computable Computational process exists that allows computing agent to complete that operation successfully Ineffectively computable example, ‘Generate a list of prime numbers’

    50. Invitation to Computer Science, C++ Version, Fourth Edition 50 The Formal Definition of an Algorithm (continued) The result of the algorithm must be produced after the execution of a finite number of operations Infinite loop The algorithm has no provisions to terminate A common error in the designing of algorithms Infinite loop example, Step 1. Wet the car Step 2. Repeat Step 3 Step 3. Wash the car

    51. Invitation to Computer Science, C++ Version, Fourth Edition 51 The Importance of Algorithmic Problem Solving Algorithmic solutions can be: Encoded into some appropriate language Given to a computing agent to execute The computing agent Would mechanically follow these instructions and successfully complete the task specified Would not have to understand Creative processes that went into discovery of solution Principles and concepts that underlie the problem

    52. Invitation to Computer Science, C++ Version, Fourth Edition 52 The Early Period: Up to 1940 3,000 years ago: Mathematics, logic, and numerical computation Important contributions made by the Greeks, Egyptians, Babylonians, Indians, Chinese, and Persians 1614: Logarithms Invented by John Napier to simplify difficult mathematical computations Around 1622: First slide rule created

    53. Invitation to Computer Science, C++ Version, Fourth Edition 53 The Early Period: Up to 1940 (continued) 1672: The Pascaline Designed and built by Blaise Pascal One of the first mechanical calculators Could do addition and subtraction 1674: Leibnitz’s Wheel Constructed by Gottfried Leibnitz Mechanical calculator Could do addition, subtraction, multiplication, and division

    54. Invitation to Computer Science, C++ Version, Fourth Edition 54 Figure 1.4 The Pascaline: One of the Earliest Mechanical Calculators

    55. Invitation to Computer Science, C++ Version, Fourth Edition 55 The Early Period: Up to 1940 (continued) 1801: The Jacquard loom Developed by Joseph Jacquard Automated loom Used punched cards to create desired pattern 1823: The Difference Engine Developed by Charles Babbage Did addition, subtraction, multiplication, and division to 6 significant digits Solved polynomial equations and other complex mathematical problems

    56. Invitation to Computer Science, C++ Version, Fourth Edition 56 The Early Period: Up to 1940 (continued) 1823: The Difference Engine Developed by Charles Babbage Capabilities: Addition, subtraction, multiplication, and division to 6 significant digits Solve polynomial equations and other complex mathematical problems

    57. Invitation to Computer Science, C++ Version, Fourth Edition 57 Figure 1.5 Drawing of the Jacquard Loom

    58. Invitation to Computer Science, C++ Version, Fourth Edition 58 The Early Period: Up to 1940 (continued) 1830s: The Analytic Engine Designed by Charles Babbage More powerful and general-purpose computational machine Components were functionally similar to the four major components of today’s computers Mill (modern terminology: arithmetic/logic unit) Store (modern terminology: memory) Operator (modern terminology: processor) Output (modern terminology: input/output)

    59. Invitation to Computer Science, C++ Version, Fourth Edition 59 The Early Period: Up to 1940 (continued) 1890: U.S. census carried out with programmable card processing machines Built by Herman Hollerith These machines could automatically read, tally, and sort data entered on punched cards

    60. Invitation to Computer Science, C++ Version, Fourth Edition 60 The Birth of Computers: 1940–1950 Development of electronic, general-purpose computers Did not begin until after 1940 Was fueled in large part by needs of World War II Early computers Mark I ENIAC ABC system Colossus Z1

    61. Invitation to Computer Science, C++ Version, Fourth Edition 61 Figure 1.6 Photograph of the ENIAC Computer

    62. Invitation to Computer Science, C++ Version, Fourth Edition 62 The Birth of Computers: 1940–1950 Stored program computer model Proposed by John Von Neumann in 1946 Stored binary algorithm in the computer’s memory along with the data Is known as the Von Neumann architecture Modern computers remain, fundamentally, Von Neumann machines First stored program computers EDVAC EDSAC

    63. Invitation to Computer Science, C++ Version, Fourth Edition 63 The Modern Era: 1950 to the Present First generation of computing (1950-1959) Used vacuum tubes to store data and programs Each computer was multiple rooms in size Computers were not very reliable

    64. Invitation to Computer Science, C++ Version, Fourth Edition 64 The Modern Era: 1950 to the Present (continued) Second generation of computing (1959-1965) Replaced vacuum tubes by transistors and magnetic cores Dramatic reduction in size Computer could fit into a single room Increase in reliability of computers Reduced costs of computers High-level programming languages The programmer occupation was born

    65. Invitation to Computer Science, C++ Version, Fourth Edition 65 The Modern Era: 1950 to the Present (continued) Third generation of computing (1965-1975) Used integrated circuits rather than individual electronic components Further reduction in size and cost of computers Computers became desk-sized First minicomputer developed Software industry formed

    66. Invitation to Computer Science, C++ Version, Fourth Edition 66 The Modern Era: 1950 to the Present (continued) Fourth generation of computing (1975-1985) Reduced to the size of a typewriter First microcomputer developed Desktop and personal computers common Appearance of Computer networks Electronic mail User-friendly systems (Graphical user interfaces) Embedded systems

    67. Invitation to Computer Science, C++ Version, Fourth Edition 67 Figure 1.7 The Altair 8800, the World’s First Microcomputer

    68. Invitation to Computer Science, C++ Version, Fourth Edition 68 The Modern Era: 1950 to the Present (continued) Fifth generation of computing (1985-?) Recent developments Massively parallel processors Handheld devices and other types of personal digital assistants (PDAs) High-resolution graphics Powerful multimedia user interfaces incorporating sound, voice recognition, touch, photography, video, and television

    69. Invitation to Computer Science, C++ Version, Fourth Edition 69 The Modern Era: 1950 to the Present (continued) Recent developments (continued) Integrated global telecommunications incorporating data, television, telephone, FAX, the Internet, and the World Wide Web Wireless data communications Massive storage devices Ubiquitous computing

    70. Invitation to Computer Science, C++ Version, Fourth Edition 70 Figure 1.8 Some of the Major Advancements in Computing

    71. Invitation to Computer Science, C++ Version, Fourth Edition 71 Figure 1.8 Some of the Major Advancements in Computing

    72. Invitation to Computer Science, C++ Version, Fourth Edition 72 Organization of the Text This book is divided into six separate sections called levels Each level addresses one aspect of the definition of computer science Computer science/Algorithms

    73. Invitation to Computer Science, C++ Version, Fourth Edition 73 Organization of the Text Level 1: The Algorithmic Foundations of Computer Science Chapters 1, 2, 3 Level 2: The Hardware World Chapters 4, 5 Level 3: The Virtual Machine Chapters 6, 7

    74. Invitation to Computer Science, C++ Version, Fourth Edition 74 Organization of the Text Level 4: The Software World Chapters 8, 9, 10, 11 Level 5: Applications Chapters 12, 13, 14 Level 6: Social Issues Chapter 15

    75. Invitation to Computer Science, C++ Version, Fourth Edition 75 Figure 1.9 Organization of the Text into a Six-Layer Hierarchy

    76. Invitation to Computer Science, C++ Version, Fourth Edition 76 Summary Computer science is the study of algorithms 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 If we can specify an algorithm to solve a problem, then we can automate its solution Computers developed from mechanical calculating devices to modern electronic marvels of miniaturization

More Related