2. Count the number of data points. 3. Total the data. 4. Divide the total by the number of data points. After the problem is decomposed into smaller steps, then those steps can be translated into instructions for the computer to perform. Writing the program is the very last step in the process. Humans solve the problem. Computers cal- culate the result. An algorithm is the sequence of steps used to solve a problem. Writing an algorithm is the last activity in computational thinking. The steps must be iden- tified by decomposing the problem. The patterns must be recognized and then generalized using abstraction. Then abstractions must be organized into the proper sequence to solve the problem. This is the algorithm. The expression of an algorithm is called pseudocode. Pseudocode is discussed further in upcoming chapters. Before there were computerized cash registers, cashiers had to make change using their own algorithms. The first step was to determine the change due the customer. They had to do subtraction in their heads! Then, they would compute how many quarters were needed, either one (.25 to .49), two (.50 to .74), or three (.75 to .99). The next step was the number of dimes, then nickels, then pennies, subtracting every time from the total due the customer. This same algorithm is used by computerized cash registers today. Often, there are many algorithms that could solve a particular problem. One goal is to find the most efficient sequence of steps that produce the result re- quired. The most efficient algorithm is often referred to as the most elegant so- lution. It is important to streamline the code. Extra steps take extra calculating time. While finding the most elegant solution may not make much difference for the programs you write in this course, programs that manage big data take many instructions. For those programs, wasted computer time means a longer wait for results. FYI Often a goal in making change is to use the fewest number of coins and bills. Certainly providing all pennies is not desired. HANDS-ON EXAMPLE 1.1.1 Creating a Perfect Squares Algorithm A perfect square is a number that has two equal factors. Perform the computational thinking required to find the first 10 perfect squares. The end result is the algorithm to solve the problem of finding perfect squares. 1. Analyze the problem to find the small, doable steps. 1. Find out how to make a perfect square. 2. Find the first perfect square. 3. Find 10 of them. 2. Find the perfect squares in the following list. Identify the equal factors for those that are perfect squares. A. 16 B. 10 C. 49 D. 5 3. Find the first perfect square. Answer: Start with the number 0. 0 × 0 = 0 4. Abstract the process. Let x = 0. Its perfect square is x × x. Copyright Goodheart-Willcox Co., Inc. Chapter 1 Computational Thinking 9
Previous Page Next Page