3.2: Use a Problem-Solving Strategy

Learning Objectives

By the end of this section, you will be able to:

• Approach word problems with a positive attitude
• Use a problem-solving strategy for word problems
• Solve number problems

Note

Before you get started, take this readiness quiz.

1. Translate “6 less than twice x” into an algebraic expression.
If you missed this problem, review Exercise 1.3.43.
2. Solve: (frac{2}{3}x=24).
If you missed this problem, review Exercise 2.2.10.
3. Solve: (3x+8=14).
If you missed this problem, review Exercise 2.3.1.

Approach Word Problems with a Positive Attitude

“If you think you can… or think you can’t… you’re right.”—Henry Ford

The world is full of word problems! Will my income qualify me to rent that apartment? How much punch do I need to make for the party? What size diamond can I afford to buy my girlfriend? Should I fly or drive to my family reunion? How much money do I need to fill the car with gas? How much tip should I leave at a restaurant? How many socks should I pack for vacation? What size turkey do I need to buy for Thanksgiving dinner, and then what time do I need to put it in the oven? If my sister and I buy our mother a present, how much does each of us pay?

Now that we can solve equations, we are ready to apply our new skills to word problems. Do you know anyone who has had negative experiences in the past with word problems? Have you ever had thoughts like the student below (Figure (PageIndex{1}))?

When we feel we have no control, and continue repeating negative thoughts, we set up barriers to success. We need to calm our fears and change our negative feelings.

Start with a fresh slate and begin to think positive thoughts. If we take control and believe we can be successful, we will be able to master word problems! Read the positive thoughts in Figure (PageIndex{2}) and say them out loud.

Think of something, outside of school, that you can do now but couldn’t do 3 years ago. Is it driving a car? Snowboarding? Cooking a gourmet meal? Speaking a new language? Your past experiences with word problems happened when you were younger—now you’re older and ready to succeed!

Use a Problem-Solving Strategy for Word Problems

We have reviewed translating English phrases into algebraic expressions, using some basic mathematical vocabulary and symbols. We have also translated English sentences into algebraic equations and solved some word problems. The word problems applied math to everyday situations. We restated the situation in one sentence, assigned a variable, and then wrote an equation to solve the problem. This method works as long as the situation is familiar and the math is not too complicated.

Now, we’ll expand our strategy so we can use it to successfully solve any word problem. We’ll list the strategy here, and then we’ll use it to solve some problems. We summarize below an effective strategy for problem solving.

USE A PROBLEM-SOLVING STRATEGY TO SOLVE WORD PROBLEMS.

1. Read the problem. Make sure all the words and ideas are understood.
2. Identify what we are looking for.
3. Name what we are looking for. Choose a variable to represent that quantity.
4. Translate into an equation. It may be helpful to restate the problem in one sentence with all the important information. Then, translate the English sentence into an algebraic equation.
5. Solve the equation using good algebra techniques.
6. Check the answer in the problem and make sure it makes sense.
7. Answer the question with a complete sentence.

Exercise (PageIndex{1})

Pilar bought a purse on sale for ($18), which is one-half of the original price. What was the original price of the purse? Answer Step 1. Read the problem. Read the problem two or more times if necessary. Look up any unfamiliar words in a dictionary or on the internet. In this problem, is it clear what is being discussed? Is every word familiar? Let p = the original price of the purse. Step 2. Identify what you are looking for. Did you ever go into your bedroom to get something and then forget what you were looking for? It’s hard to find something if you are not sure what it is! Read the problem again and look for words that tell you what you are looking for! In this problem, the words “what was the original price of the purse” tell us what we need to find. Step 3. Name what we are looking for. Choose a variable to represent that quantity. We can use any letter for the variable, but choose one that makes it easy to remember what it represents. Step 4. Translate into an equation. Translate the English sentence into an algebraic equation. Reread the problem carefully to see how the given information is related. Often, there is one sentence that gives this information, or it may help to write one sentence with all the important information. Look for clue words to help translate the sentence into algebra. Translate the sentence into an equation.  Restate the problem in one sentence with all the important information. (color{cyan} underbrace{strut color{black}mathbf{18}} quad underbrace{strut color{black} extbf{ is }} quad underbrace{color{black} extbf{one-half the original price.}}) Translate into an equation. (18 qquad = qquad qquad qquad frac{1}{2}cdot p) Step 5. Solve the equation using good algebraic techniques. Even if you know the solution right away, using good algebraic techniques here will better prepare you to solve problems that do not have obvious answers.  Solve the equation. (18 = frac{1}{2}p) Multiply both sides by 2. ( {color{red}{2}}cdot 18 = {color{red}{2}}cdot frac{1}{2}p ) Simplify. (36 = p) Step 6. Check the answer in the problem to make sure it makes sense. We solved the equation and found that (p=36),which means “the original price” was ($36).

Does $36 make sense in the problem? Yes, because 18 is one-half of 36, and the purse was on sale at half the original price. If this were a homework exercise, our work might look like this: Pilar bought a purse on sale for ($18), which is one-half the original price. What was the original price of the purse?

Step 7. Answer the question with a complete sentence. The problem asked “What was the original price of the purse?”

The answer to the question is: “The original price of the purse was $36.”  Let (p =) the original price. (18) is one-half the original price. (18 = frac{1}{2}p) Multiply both sides by (2). ( {color{red}{2}}cdot 18 = {color{red}{2}}cdot frac{1}{2}p ) Simplify. (36 = p) Check. Is ($36) a reasonable price for a purse? Yes. Is (18) one half of (36)? (18 stackrel{?}{=} frac{1}{2}cdot 36) (18 = 18checkmark) The original price of the purse was ($36). Exercise (PageIndex{2}) Joaquin bought a bookcase on sale for ($120), which was two-thirds of the original price. What was the original price of the bookcase?

($180) Exercise (PageIndex{3}) Two-fifths of the songs in Mariel’s playlist are country. If there are (16) country songs, what is the total number of songs in the playlist? Answer (40) Let’s try this approach with another example. Exercise (PageIndex{4}) Ginny and her classmates formed a study group. The number of girls in the study group was three more than twice the number of boys. There were (11) girls in the study group. How many boys were in the study group? Answer  Step 1. Read the problem. Step 2. Identify what we are looking for. How many boys were in the study group? Step 3. Name. Choose a variable to represent the number of boys. Let (n=) the number of boys. Step 4. Translate. Restate the problem in one sentence with all the important information. (color{cyan} underbrace{color{black} extbf{The number} color{black} extbf{of girls}(11)} quad underbrace{strut ext{ } color{black} extbf{was}} quad underbrace{color{black} extbf{three more than} color{black} extbf{twice the number of boys}}) Translate into an equation. (qquad 11 qquad quad = qquad qquad quad 2b + 3) Step 5. Solve the equation. (quad 11 = 2b + 3 ) Subtract 3 from each side. Simplify. (quad 8 = 2b ) Divide each side by 2. ( quad dfrac{8}{color{red}{2}}=dfrac{2b}{color{red}{2}} ) Simplify. (quad 4 = b) Step 6. Check. First, is our answer reasonable? Yes, having (4) boys in a study group seems OK. The problem says the number of girls was (3) more than twice the number of boys. If there are four boys, does that make eleven girls? Twice (4) boys is (8). Three more than (8) is (11). Step 7. Answer the question. There were (4) boys in the study group. Exercise (PageIndex{5}) Guillermo bought textbooks and notebooks at the bookstore. The number of textbooks was (3) more than twice the number of notebooks. He bought (7) textbooks. How many notebooks did he buy? Answer (2) Exercise (PageIndex{6}) Gerry worked Sudoku puzzles and crossword puzzles this week. The number of Sudoku puzzles he completed is eight more than twice the number of crossword puzzles. He completed (22) Sudoku puzzles. How many crossword puzzles did he do? Answer (7) Solve Number Problems Now that we have a problem solving strategy, we will use it on several different types of word problems. The first type we will work on is “number problems.” Number problems give some clues about one or more numbers. We use these clues to write an equation. Number problems don’t usually arise on an everyday basis, but they provide a good introduction to practicing the problem solving strategy outlined above. Exercise (PageIndex{7}) The difference of a number and six is (13). Find the number. Answer  Step 1. Are all the words familiar? Step 2. Identify what we are looking for. the number Step 3. Name. Choose a variable to represent the number. Let (n=) the number. Step 4. Translate. Remember to look for clue words like "difference... of... and..." Restate the problem as one sentence. (color{cyan} underbrace{color{black} extbf{The difference of the number and }mathbf{6}} quad underbrace{strut color{black} extbf{ is }} quad underbrace{strut color{black}mathbf{13}}) Translate into an equation. Step 5. Solve the equation. Simplify. (quad n =19) Step 6. Check. The difference of (19) and (6) is (13). It checks! Step 7. Answer the question. The number is (19). Exercise (PageIndex{8}) The difference of a number and eight is (17). Find the number. Answer (25) Exercise (PageIndex{9}) The difference of a number and eleven is (−7). Find the number. Answer (4) Exercise (PageIndex{11}) The sum of four times a number and two is (14). Find the number. Answer (3) Exercise (PageIndex{12}) The sum of three times a number and seven is (25). Find the number. Answer (6) ​​​​​​Some number word problems ask us to find two or more numbers. It may be tempting to name them all with different variables, but so far we have only solved equations with one variable. In order to avoid using more than one variable, we will define the numbers in terms of the same variable. Be sure to read the problem carefully to discover how all the numbers relate to each other. Exercise (PageIndex{14}) One number is six more than another. The sum of the numbers is twenty-four. Find the numbers. Answer 9, 15 Exercise (PageIndex{15}) The sum of two numbers is fifty-eight. One number is four more than the other. Find the numbers. Answer 27, 31 Exercise (PageIndex{17}) The sum of two numbers is negative twenty-three. One number is seven less than the other. Find the numbers. Answer -15, -8 Exercise (PageIndex{18}) The sum of two numbers is (−18). One number is (40) more than the other. Find the numbers. Answer -29, 11 Exercise (PageIndex{20}) One number is eight more than twice another. Their sum is negative four. Find the numbers. Answer (-4,; 0) Exercise (PageIndex{21}) One number is three more than three times another. Their sum is (−5). Find the numbers. Answer (-3,; -2) Some number problems involve consecutive integers. Consecutive integers are integers that immediately follow each other. Examples of consecutive integers are: [egin{array}{l}{1,2,3,4} {-10,-9,-8,-7} {150,151,152,153}end{array}] Notice that each number is one more than the number preceding it. So if we define the first integer as (n), the next consecutive integer is (n+1). The one after that is one more than (n+1), so it is (n+1+1), which is (n+2). [egin{array}{ll}{n} & {1^{ ext { st }} ext { integer }} {n+1} & {2^{ ext { nd }} ext { consecutive integer }} {n+2} & {3^{ ext { rd }} ext { consecutive integer } ldots ext { etc. }}end{array}] Exercise (PageIndex{23}) The sum of two consecutive integers is 95. Find the numbers. Answer 47, 48 Exercise (PageIndex{24}) The sum of two consecutive integers is −31. Find the numbers. Answer -16, -15 Exercise (PageIndex{26}) Find three consecutive integers whose sum is −96. Answer -33, -32, -31 Exercise (PageIndex{27}) Find three consecutive integers whose sum is −36. Answer -13, -12, -11 Now that we have worked with consecutive integers, we will expand our work to include consecutive even integers and consecutive odd integers. Consecutive even integers are even integers that immediately follow one another. Examples of consecutive even integers are: [egin{array}{l}{18,20,22} {64,66,68} {-12,-10,-8}end{array}] Notice each integer is (2) more than the number preceding it. If we call the first one (n), then the next one is (n+2). The next one would be (n+2+2) or (n+4). [egin{array}{cll}{n} & {1^{ ext { st }} ext { even integer }} {n+2} & {2^{ ext { nd }} ext { consecutive even integer }} {n+4} & {3^{ ext { rd }} ext { consecutive even integer } ldots ext { etc. }}end{array}] Consecutive odd integers are odd integers that immediately follow one another. Consider the consecutive odd integers (77), (79), and (81). [egin{array}{l}{77,79,81} {n, n+2, n+4}end{array}] [egin{array}{cll}{n} & {1^{ ext { st }} ext {odd integer }} {n+2} & {2^{ ext { nd }} ext { consecutive odd integer }} {n+4} & {3^{ ext { rd }} ext { consecutive odd integer } ldots ext { etc. }}end{array}] Does it seem strange to add 2 (an even number) to get from one odd integer to the next? Do you get an odd number or an even number when we add 2 to 3? to 11? to 47? Whether the problem asks for consecutive even numbers or odd numbers, you don’t have to do anything different. The pattern is still the same—to get from one odd or one even integer to the next, add 2. Exercise (PageIndex{28}) Find three consecutive even integers whose sum is 84. Answer [egin{array}{ll} { extbf{Step 1. Read} ext{ the problem.}} & {} { extbf{Step 2. Identify} ext{ what we are looking for.}} & { ext{three consecutive even integers}} { extbf{Step 3. Name} ext{ the integers.}} & { ext{Let } n = 1^{st} ext{ even integers.}} {} &{n + 2 = 2^{nd} ext{ consecutive even integer}} {} &{n + 4 = 3^{rd} ext{ consecutive even integer}} { extbf{Step 4. Translate.}} &{} { ext{ Restate as one sentence. }} &{ ext{The sum of the three even integers is 84.}} { ext{Translate into an equation.}} &{n + n + 2 + n + 4 = 84} { extbf{Step 5. Solve} ext{ the equation. }} &{} { ext{Combine like terms.}} &{n + n + 2 + n + 4 = 84} { ext{Subtract 6 from each side.}} &{3n + 6 = 84} { ext{Divide each side by 3.}} &{3n = 78} {} &{n = 26 space 1^{st} ext{ integer}} {} &{n + 2space 2^{nd} ext{ integer}} {} &{26 + 2} {} &{28} {} &{n + 4space 3^{rd} ext{ integer}} {} &{26 + 4} {} &{30} { extbf{Step 6. Check.}} &{} {26 + 28 + 30 stackrel{?}{=} 84} &{} {84 = 84 checkmark} & {} { extbf{Step 7. Answer} ext{ the question.}} &{ ext{The three consecutive integers are 26, 28, and 30.}} end{array}] Exercise (PageIndex{29}) Find three consecutive even integers whose sum is 102. Answer 32, 34, 36 Exercise (PageIndex{30}) Find three consecutive even integers whose sum is −24. Answer −10,−8,−6 Exercise (PageIndex{31}) A married couple together earns$110,000 a year. The wife earns $16,000 less than twice what her husband earns. What does the husband earn? Answer  Step 1. Identify what we are looking for. How much does the husband earn? Step 3. Name. Choose a variable to represent the amountthe husband earns. Let (h=) the amount the husband earns. The wife earns ($16,000) less than twice that. (2h−16,000) the amount the wife earns. Step 4. Together the husband and wife earn ($110,000). Restate the problem in one sentence withall the important information. Translate into an equation. Step 5. Solve the equation. (h + 2h − 16,000 = 110,000) Combine like terms. (3h − 16,000 = 110,000) Add (16,000) to both sides and simplify. (3h = 126,000) Divide each side by (3). (h = 42,000) ($42,000) amount husband earns (2h − 16,000) amount wife earns (2(42,000) − 16,000) (84,000 − 16,000) (68,000) Step 6. Check. If the wife earns ($68,000) and the husband earns ($42,000) is the total ($110,000)(? Yes! Step 7. Answer the question. The husband earns ($42,000) a year.

Exercise (PageIndex{32})

According to the National Automobile Dealers Association, the average cost of a car in 2014 was $28,500. This was$1,500 less than 6 times the cost in 1975. What was the average cost of a car in 1975?

$5000 Exercise (PageIndex{33}) U.S. Census data shows that the median price of new home in the United States in November 2014 was$280,900. This was $10,700 more than 14 times the price in November 1964. What was the median price of a new home in November 1964? Answer$19300

Key Concepts

• Problem-Solving Strategy
1. Read the problem. Then, translate the English sentence into an algebra equation.
2. Solve the equation using good algebra techniques.
3. Check the answer in the problem and make sure it makes sense.
4. Answer the question with a complete sentence.
• Consecutive Integers
Consecutive integers are integers that immediately follow each other.

[egin{array}{cc}{n} & {1^{ ext { st }} ext { integer }} {n+1} & {2^{ ext { nd }} ext {consecutive integer }} {n+2} & {3^{ ext { rd }} ext { consecutive integer } ldots ext { etc. }}end{array}]

Consecutive even integers are even integers that immediately follow one another.

[egin{array}{cc}{n} & {1^{ ext { st }} ext { integer }} {n+2} & {2^{ ext { nd }} ext { consecutive even integer }} {n+4} & {3^{ ext { rd }} ext { consecutive even integer } ldots ext { etc. }}end{array}]

Consecutive odd integers are odd integers that immediately follow one another.

[egin{array}{cc}{n} & {1^{ ext { st }} ext { integer }} {n+2} & {2^{ ext { nd }} ext { consecutive odd integer }} {n+4} & {3^{ ext { rd }} ext { consecutive odd integer } ldots ext { etc. }}end{array}]

First on the list we have is a strategy that was introduced by Bransford and Stein in 1984. It’s called the “IDEAL” approach of problem solving. Let’s break it down.

I – Identify the problem

E – Explore possible strategies

Let’s learn about each letters in IDEAL problem solving strategy.

First is I dentifying the problem. Rather than going with the blame game, try to find what exactly is the problem? The real problem may not be the one that you’re facing right now. For example: Sales team failed to meet targets this year. Rather than blaming entirely on the sales, try to find what caused them to fail this month. May be there was not enough support from development team to improve the product or support team wasn’t helping. There’s always a cause that leads to a problem, that’s the first step.

Second is D efining the cause. After finding out all the possible reasons, define the problem in one line. What exactly is the problem? Not the situation that you’re facing because that can be one of the results of the main cause. Define the cause, in one simple line. Defining the cause can save you from many upcoming problems. For example, if a company failed to perform to complete a task on time, and the cause is “Weak communication between teams”, there more than one problems that can be solved by solving the cause.

To solve “weak communication between teams”, you can implement various tools for communication. By solving the cause, work productivity can also be improved. The time taken for tasks will reduce, and average time to complete a project will reduce. Hence, solving a case will solve multiple problems.

Third is E xploring possible strategies. Now that you know the cause that formed the problem, again you have to brainstorm. Think about all the possible solutions and strategies that can be easily implemented at your workplace. You should definitely take suggestions from your teammates, as they have suffered the problem.

The fourth step is to A ct. Choose from the list of possible solutions and start acting on it. Here’s the fun about not wasting your time and killing productivity. When you try a new solution quickly, you will see the changes very quickly as well. Now, if you think a particular solution is not solving the problem, you can quickly shift to the next solution. That way, you’ll find the needed workflow in a short span.

The last one is to L ook back and L earn because there’s always some learning. There’s a great quote from Robert H. Schuller, “Problems are not stop signs, they are guidelines.” Stopping the problem was not in your hand at some point, but you can stop the upcoming bizarre events by learning a lesson.

Get to know the problem by asking questions and getting all pertinent information out in the open.

• When was the last time this system worked correctly?
• When did this issue arise?

Wrap up this step by creating a one-sentence definition of the problem.

Revise/edit this sentence (as a group) until it clearly and succinctly represents your challenge/goal.

Finding Patterns in Math Problems:

So when should kids use problem solving by finding a pattern? Well, when the problem gives a set of data, or a pattern that is continuing and can be arranged in a table, it’s good to consider looking for the pattern and determining the “rule” of the pattern.

As I mentioned when I discussed problem solving by making a list, finding a pattern can be immensely helpful and save a lot of time when working on a word problem. Sometimes, however, a student may not recognize the pattern right away, or may get bogged down with all the details of the question.

Setting up a table and filling in the information given in the question is a great way to organize things and provide a visual so that the “rule” of the pattern can be determined. The “rule” can then be used to find the answer to the question. This removes the tedious work of completing a table, which is especially nice if a lot of computation is involved.

But a table is also great for kids who struggle with math, because it gives them a way to get to the solution even if they have a hard time finding the pattern, or aren’t confident that they are using the “rule” correctly.

Because even though using a known pattern can save you time, and eliminate the need to fill out the entire table, it’s not necessary. A student who is unsure could simply continue filling out their table until they reach the solution they’re looking for.

Helping students learn how to set up a table is also helpful because they can use it to organize information (much like making a list) even if there isn’t a pattern to be found, because it can be done in a systematic way, ensuring that nothing is left out.

If your students are just learning how to read and create tables, I would suggest having them circle their answer in the table to show that they understood the question and knew where in the table to find the answer.

If you have older students, encourage them to find a pattern in the table and explain it in words, and then also with mathematical symbols and/or an equation. This will help them form connections and increase number sense. It will also help them see how to use their “rule” or equation to solve the given question as well as make predictions about the data.

It’s also important for students to consider whether or not their pattern will continue predictably. In some instances, the pattern may look one way for the first few entries, then change, so this is important to consider as the problems get more challenging.

There are tons of examples of problems where creating a table and finding a pattern is a useful strategy, but here’s just one example for you:

Ben decides to prepare for a marathon by running ten minutes a day, six days a week. Each week, he increases his time running by two minutes per day. How many minutes will he run in week 8?

Included in the table is the week number (we’re looking at weeks 1-8), as well as the number of minutes per day and the total minutes for the week. The first step is to fill in the first couple of weeks by calculating the total time.

Once you’ve found weeks 1-3, you may see a pattern and be able to calculate the total minutes for week 8. For example, in this case, the total number of minutes increases by 12 each week, meaning in week 8 he will run for 144 minutes.

If not, however, simply continue with the table until you get to week 8, and then you will have your answer.

I think it is especially important to make it clear to students that it is perfectly acceptable to complete the entire table (or continue a given table) if they don’t see or don’t know how to use the pattern to solve the problem.

I was working with a student once and she was given a table, but was then asked a question about information not included in that table. She was able to tell me the pattern she saw, but wasn’t able to correctly use the “rule” to find the answer. I insisted that she simply extend the table until she found what she needed. Then I showed her how to use the “rule” of the pattern to get the same answer.

I hope you find this helpful! Looking for and finding patterns is such an essential part of mathematics education! If you’re looking for more ideas for exploring patterns, check out this huge post of “Ideas for teaching patterns to preschoolers.”

Never Run Out of Fun Math Ideas

If you enjoyed this post, you will love being a part of the Math Geek Mama community! Each week I send an email with fun and engaging math ideas, free resources and special offers. Join 124,000+ readers as we help every child succeed and thrive in math! PLUS, receive my FREE ebook, 5 Math Games You Can Play TODAY, as my gift to you!

I had so much trouble spotting patterns when I was in school. Fortunately for her, my daughter rocks at it! This technique will be helpful for her when she’s a bit older! #ThoughtfulSpot

Math Time Doesn't Have to End in Tears

Join 130,000+ parents and teachers who learn new tips and strategies, as well as receive engaging resources to make math fun. Plus, receive my guide, "5 Games You Can Play Today to Make Math Fun," as my free gift to get you started!

3.2. What Is Algorithm Analysis?¶

It is very common for beginning computer science students to compare their programs with one another. You may also have noticed that it is common for computer programs to look very similar, especially the simple ones. An interesting question often arises. When two programs solve the same problem but look different, is one program better than the other?

In order to answer this question, we need to remember that there is an important difference between a program and the underlying algorithm that the program is representing. As we stated in Chapter 1, an algorithm is a generic, step-by-step list of instructions for solving a problem. It is a method for solving any instance of the problem such that given a particular input, the algorithm produces the desired result. A program, on the other hand, is an algorithm that has been encoded into some programming language. There may be many programs for the same algorithm, depending on the programmer and the programming language being used.

To explore this difference further, consider the function shown in ActiveCode 1 . This function solves a familiar problem, computing the sum of the first n integers. The algorithm uses the idea of an accumulator variable that is initialized to 0. The solution then iterates through the n integers, adding each to the accumulator.

Now look at the function in ActiveCode 2 . At first glance it may look strange, but upon further inspection you can see that this function is essentially doing the same thing as the previous one. The reason this is not obvious is poor coding. We did not use good identifier names to assist with readability, and we used an extra assignment statement during the accumulation step that was not really necessary.

The question we raised earlier asked whether one function is better than another. The answer depends on your criteria. The function sumOfN is certainly better than the function foo if you are concerned with readability. In fact, you have probably seen many examples of this in your introductory programming course since one of the goals there is to help you write programs that are easy to read and easy to understand. In this course, however, we are also interested in characterizing the algorithm itself. (We certainly hope that you will continue to strive to write readable, understandable code.)

Algorithm analysis is concerned with comparing algorithms based upon the amount of computing resources that each algorithm uses. We want to be able to consider two algorithms and say that one is better than the other because it is more efficient in its use of those resources or perhaps because it simply uses fewer. From this perspective, the two functions above seem very similar. They both use essentially the same algorithm to solve the summation problem.

At this point, it is important to think more about what we really mean by computing resources. There are two different ways to look at this. One way is to consider the amount of space or memory an algorithm requires to solve the problem. The amount of space required by a problem solution is typically dictated by the problem instance itself. Every so often, however, there are algorithms that have very specific space requirements, and in those cases we will be very careful to explain the variations.

As an alternative to space requirements, we can analyze and compare algorithms based on the amount of time they require to execute. This measure is sometimes referred to as the “execution time” or “running time” of the algorithm. One way we can measure the execution time for the function sumOfN is to do a benchmark analysis. This means that we will track the actual time required for the program to compute its result. In Python, we can benchmark a function by noting the starting time and ending time with respect to the system we are using. In the time module there is a function called time that will return the current system clock time in seconds since some arbitrary starting point. By calling this function twice, at the beginning and at the end, and then computing the difference, we can get an exact number of seconds (fractions in most cases) for execution.

Listing 1 shows the original sumOfN function with the timing calls embedded before and after the summation. The function returns a tuple consisting of the result and the amount of time (in seconds) required for the calculation. If we perform 5 invocations of the function, each computing the sum of the first 10,000 integers, we get the following:

We discover that the time is fairly consistent and it takes on average about 0.0019 seconds to execute that code. What if we run the function adding the first 100,000 integers?

Again, the time required for each run, although longer, is very consistent, averaging about 10 times more seconds. For n equal to 1,000,000 we get:

In this case, the average again turns out to be about 10 times the previous.

Now consider ActiveCode 3 , which shows a different means of solving the summation problem. This function, sumOfN3 , takes advantage of a closed equation (sum_^ i = frac <(n)(n+1)><2>) to compute the sum of the first n integers without iterating.

If we do the same benchmark measurement for sumOfN3 , using five different values for n (10,000, 100,000, 1,000,000, 10,000,000, and 100,000,000), we get the following results:

There are two important things to notice about this output. First, the times recorded above are shorter than any of the previous examples. Second, they are very consistent no matter what the value of n . It appears that sumOfN3 is hardly impacted by the number of integers being added.

But what does this benchmark really tell us? Intuitively, we can see that the iterative solutions seem to be doing more work since some program steps are being repeated. This is likely the reason it is taking longer. Also, the time required for the iterative solution seems to increase as we increase the value of n . However, there is a problem. If we ran the same function on a different computer or used a different programming language, we would likely get different results. It could take even longer to perform sumOfN3 if the computer were older.

We need a better way to characterize these algorithms with respect to execution time. The benchmark technique computes the actual time to execute. It does not really provide us with a useful measurement, because it is dependent on a particular machine, program, time of day, compiler, and programming language. Instead, we would like to have a characterization that is independent of the program or computer being used. This measure would then be useful for judging the algorithm alone and could be used to compare algorithms across implementations.

3.2. What Is Algorithm Analysis?¶

It is very common for beginning computer science students to compare their programs with one another. You may also have noticed that it is common for computer programs to look very similar, especially the simple ones. An interesting question often arises. When two programs solve the same problem but look different, is one program better than the other?

In order to answer this question, we need to remember that there is an important difference between a program and the underlying algorithm that the program is representing. As we stated in Chapter 1, an algorithm is a generic, step-by-step list of instructions for solving a problem. It is a method for solving any instance of the problem such that given a particular input, the algorithm produces the desired result. A program, on the other hand, is an algorithm that has been encoded into some programming language. There may be many programs for the same algorithm, depending on the programmer and the programming language being used.

To explore this difference further, consider the function shown in ActiveCode 1 . This function solves a familiar problem, computing the sum of the first n integers. The algorithm uses the idea of an accumulator variable that is initialized to 0. The solution then iterates through the n integers, adding each to the accumulator.

Now look at the function in ActiveCode 2 . At first glance it may look strange, but upon further inspection you can see that this function is essentially doing the same thing as the previous one. The reason this is not obvious is poor coding. We did not use good identifier names to assist with readability, and we used an extra assignment statement during the accumulation step that was not really necessary.

The question we raised earlier asked whether one function is better than another. The answer depends on your criteria. The function sumOfN is certainly better than the function foo if you are concerned with readability. In fact, you have probably seen many examples of this in your introductory programming course since one of the goals there is to help you write programs that are easy to read and easy to understand. In this course, however, we are also interested in characterizing the algorithm itself. (We certainly hope that you will continue to strive to write readable, understandable code.)

Algorithm analysis is concerned with comparing algorithms based upon the amount of computing resources that each algorithm uses. We want to be able to consider two algorithms and say that one is better than the other because it is more efficient in its use of those resources or perhaps because it simply uses fewer. From this perspective, the two functions above seem very similar. They both use essentially the same algorithm to solve the summation problem.

At this point, it is important to think more about what we really mean by computing resources. There are two different ways to look at this. One way is to consider the amount of space or memory an algorithm requires to solve the problem. The amount of space required by a problem solution is typically dictated by the problem instance itself. Every so often, however, there are algorithms that have very specific space requirements, and in those cases we will be very careful to explain the variations.

As an alternative to space requirements, we can analyze and compare algorithms based on the amount of time they require to execute. This measure is sometimes referred to as the “execution time” or “running time” of the algorithm. One way we can measure the execution time for the function sumOfN is to do a benchmark analysis. This means that we will track the actual time required for the program to compute its result. In Python, we can benchmark a function by noting the starting time and ending time with respect to the system we are using. In the time module there is a function called time that will return the current system clock time in seconds since some arbitrary starting point. By calling this function twice, at the beginning and at the end, and then computing the difference, we can get an exact number of seconds (fractions in most cases) for execution.

Listing 1 shows the original sumOfN function with the timing calls embedded before and after the summation. The function returns a tuple consisting of the result and the amount of time (in seconds) required for the calculation. If we perform 5 invocations of the function, each computing the sum of the first 10,000 integers, we get the following:

We discover that the time is fairly consistent and it takes on average about 0.0019 seconds to execute that code. What if we run the function adding the first 100,000 integers?

Again, the time required for each run, although longer, is very consistent, averaging about 10 times more seconds. For n equal to 1,000,000 we get:

In this case, the average again turns out to be about 10 times the previous.

Now consider ActiveCode 3 , which shows a different means of solving the summation problem. This function, sumOfN3 , takes advantage of a closed equation (sum_^ i = frac <(n)(n+1)><2>) to compute the sum of the first n integers without iterating.

If we do the same benchmark measurement for sumOfN3 , using five different values for n (10,000, 100,000, 1,000,000, 10,000,000, and 100,000,000), we get the following results:

There are two important things to notice about this output. First, the times recorded above are shorter than any of the previous examples. Second, they are very consistent no matter what the value of n . It appears that sumOfN3 is hardly impacted by the number of integers being added.

But what does this benchmark really tell us? Intuitively, we can see that the iterative solutions seem to be doing more work since some program steps are being repeated. This is likely the reason it is taking longer. Also, the time required for the iterative solution seems to increase as we increase the value of n . However, there is a problem. If we ran the same function on a different computer or used a different programming language, we would likely get different results. It could take even longer to perform sumOfN3 if the computer were older.

We need a better way to characterize these algorithms with respect to execution time. The benchmark technique computes the actual time to execute. It does not really provide us with a useful measurement, because it is dependent on a particular machine, program, time of day, compiler, and programming language. Instead, we would like to have a characterization that is independent of the program or computer being used. This measure would then be useful for judging the algorithm alone and could be used to compare algorithms across implementations.

Stage 5. Postpurchase Use and Evaluation

At this point in the process you decide whether the backpack you purchased is everything it was cracked up to be. Hopefully it is. If it’s not, you’re likely to suffer what’s called postpurchase dissonance . You might call it buyer’s remorse. Typically, dissonance occurs when a product or service does not meet your expectations. Consumers are more likely to experience dissonance with products that are relatively expensive and that are purchased infrequently.

You want to feel good about your purchase, but you don’t. You begin to wonder whether you should have waited to get a better price, purchased something else, or gathered more information first. Consumers commonly feel this way, which is a problem for sellers. If you don’t feel good about what you’ve purchased from them, you might return the item and never purchase anything from them again. Or, worse yet, you might tell everyone you know how bad the product was.

Companies do various things to try to prevent buyer’s remorse. For smaller items, they might offer a money back guarantee or they might encourage their salespeople to tell you what a great purchase you made. How many times have you heard a salesperson say, “That outfit looks so great on you!” For larger items, companies might offer a warranty, along with instruction booklets, and a toll-free troubleshooting line to call or they might have a salesperson call you to see if you need help with product. Automobile companies may offer loaner cars when you bring your car in for service.

Companies may also try to set expectations in order to satisfy customers. Service companies such as restaurants do this frequently. Think about when the hostess tells you that your table will be ready in 30 minutes. If they seat you in 15 minutes, you are much happier than if they told you that your table would be ready in 15 minutes, but it took 30 minutes to seat you. Similarly, if a store tells you that your pants will be altered in a week and they are ready in three days, you’ll be much more satisfied than if they said your pants would be ready in three days, yet it took a week before they were ready.

Determine the Causes

Fishbone Diagram

Once you have defined the problem, you are ready to dig deeper and start to determine what is causing it.  You can use a fishbone diagram to help you perform a cause and effect analysis.

If you consider the problem as a gap between where you are now and where you want to be, the causes of the problem are the obstacles that are preventing you from closing that gap immediately.

This level of analysis is important to make sure your solutions address the actual causes of the problem instead of the symptoms of the problem. If your solution fixes a symptom instead of an actual cause, the problem is likely to reoccur since it was never truly solved.

Use a Problem Solving Strategy

Translate “six less than twice x” into an algebraic expression.

If you missed this problem, review [link].

If you missed this problem, review [link].

If you missed this problem, review [link].

Have you ever had any negative experiences in the past with word problems? When we feel we have no control, and continue repeating negative thoughts, we set up barriers to success. Realize that your negative experiences with word problems are in your past. To move forward you need to calm your fears and change your negative feelings.

Start with a fresh slate and begin to think positive thoughts. Repeating some of the following statements may be helpful to turn your thoughts positive. Thinking positive thoughts is a first step towards success.

I think I can! I think I can!

While word problems were hard in the past, I think I can try them now.

I am better prepared now—I think I will begin to understand word problems.

I am able to solve equations because I practiced many problems and I got help when I needed it—I can try that* * *

It may take time, but I can begin to solve word problems.

You are now well prepared and you are ready to succeed. If you take control and believe you can be successful, you will be able to master word problems.

Use a Problem Solving Strategy for Word Problems

Now that we can solve equations, we are ready to apply our new skills to word problems. We will develop a strategy we can use to solve any word problem successfully.

Normal yearly snowfall at the local ski resort is 12 inches more than twice the amount it received last season. The normal yearly snowfall is 62 inches. What was the snowfall last season at the ski resort?

 Step 1. Read the problem. Step 2. Identify what you are looking for. What was the snowfall last season? Step 3. Name what we are looking for and choose a variable to represent it. Let s = the snowfall last season. Step 4. Translate. Restate the problem in one sentence with all the important information. Translate into an equation. Step 5. Solve the equation. Subtract 12 from each side. Simplify. Divide each side by two. Simplify. Step 6. Check: First, is our answer reasonable? Yes, having 25 inches of snow seems OK. The problem says the normal snowfall is twelve inches more than twice the number of last season. Twice 25 is 50 and 12 more than that is 62. Step 7. Answer the question. The snowfall last season was 25 inches.

Guillermo bought textbooks and notebooks at the bookstore. The number of textbooks was three more than twice the number of notebooks. He bought seven textbooks. How many notebooks did he buy?

Gerry worked Sudoku puzzles and crossword puzzles this week. The number of Sudoku puzzles he completed is eight more than twice the number of crossword puzzles. He completed 22 Sudoku puzzles. How many crossword puzzles did he do?

He did seven crosswords puzzles.

We summarize an effective strategy for problem solving.

1. Read the problem. Make sure all the words and ideas are understood.
2. Identify what you are looking for.
3. Name what you are looking for. Choose a variable to represent that quantity.
4. Translate into an equation. It may be helpful to restate the problem in one sentence with all the important information. Then, translate the English sentence into an algebra equation.
5. Solve the equation using proper algebra techniques.
6. Check the answer in the problem to make sure it makes sense.
7. Answer the question with a complete sentence.

Solve Number Word Problems

We will now apply the problem solving strategy to “number word problems.” Number word problems give some clues about one or more numbers and we use these clues to write an equation. Number word problems provide good practice for using the Problem Solving Strategy.

The sum of seven times a number and eight is thirty-six. Find the number.

 Step 1. Read the problem. Step 2. Identify what you are looking for. the number Step 3. Name what you are looking for and choose a variable to represent it. Let n = the number. Step 4. Translate: Restate the problem as one sentence. Translate into an equation. Step 5. Solve the equation. Subtract eight from each side and simplify. Divide each side by seven and simplify. Step 6. Check. Is the sum of seven times four plus eight equal to 36? 7 · 4 + 8 = ? 36 28 + 8 = ? 36 36 = 36 ✓ Step 7. Answer the question. The number is 4.

Did you notice that we left out some of the steps as we solved this equation? If you’re not yet ready to leave out these steps, write down as many as you need.

The sum of four times a number and two is fourteen. Find the number.

The sum of three times a number and seven is twenty-five. Find the number.

Some number word problems ask us to find two or more numbers. It may be tempting to name them all with different variables, but so far, we have only solved equations with one variable. In order to avoid using more than one variable, we will define the numbers in terms of the same variable. Be sure to read the problem carefully to discover how all the numbers relate to each other.

The sum of two numbers is negative fifteen. One number is nine less than the other. Find the numbers.

 Step 1. Read the problem. Step 2. Identify what you are looking for. two numbers Step 3. Name what you are looking for by choosing a variable to represent the first number. “One number is nine less than the other.” Let n = 1 st number. n − 9 = 2 nd number Step 4. Translate. Write as one sentence. Translate into an equation. The sum of two numbers is negative fifteen. Step 5. Solve the equation. Combine like terms. Add nine to each side and simplify. Simplify. Step 6. Check. Is −12 nine less than −3 ? −3 − 9 = ? − 12 −12 = −12 ✓ Is their sum −15 ? −3 + ( −12 ) = ? − 15 −15 = −15 ✓ Step 7. Answer the question. The numbers are −3 and −12 .

The sum of two numbers is negative twenty-three. One number is seven less than the other. Find the numbers.

The sum of two numbers is negative eighteen. One number is forty more than the other. Find the numbers.

Some number problems involve consecutive integers. Consecutive integers are integers that immediately follow each other. Examples of consecutive integers are:

Notice that each number is one more than the number preceding it. Therefore, if we define the first integer as n, the next consecutive integer is n + 1 .

The one after that is one more than n + 1 ,

We will use this notation to represent consecutive integers in the next example.

Find three consecutive integers whose sum is −54 .

 Step 1. Read the problem. Step 2. Identify what you are looking for. three consecutive integers Step 3. Name each of the three numbers Let n = 1 st integer. n + 1 = 2 nd consecutive integer n + 2 = 3 rd consecutive integer Step 4. Translate. Restate as one sentence. Translate into an equation. The sum of the three integers is −54 . Step 5. Solve the equation. Combine like terms. Subtract three from each side. Divide each side by three. Step 6. Check. −19 + ( −18 ) + ( −17 ) = −54 −54 = −54 ✓ Step 7. Answer the question. The three consecutive integers are −17 , − 18, and −19 .

Find three consecutive integers whose sum is −96 .

Find three consecutive integers whose sum is −36 .

Now that we have worked with consecutive integers, we will expand our work to include consecutive even integers and consecutive odd integers. Consecutive even integers are even integers that immediately follow one another. Examples of consecutive even integers are:

Notice each integer is two more than the number preceding it. If we call the first one n, then the next one is n + 2 .

The one after that would be n + 2 + 2

Consecutive odd integers are odd integers that immediately follow one another. Consider the consecutive odd integers 63, 65, and 67.

Does it seem strange to have to add two (an even number) to get the next odd number? Do we get an odd number or an even number when we add 2 to 3? to 11? to 47?

Whether the problem asks for consecutive even numbers or odd numbers, you do not have to do anything different. The pattern is still the same—to get to the next odd or the next even integer, add two.

Find three consecutive even integers whose sum is 120

Find three consecutive even integers whose sum is 102.

Find three consecutive even integers whose sum is −24 .

When a number problem is in a real life context, we still use the same strategies that we used for the previous examples.

A married couple together earns $110,000 a year. The wife earns$16,000 less than twice what her husband earns. What does the husband earn?

According to the National Automobile Dealers Association, the average cost of a car in 2014 was $28,400. This was$1,600 less than six times the cost in 1975. What was the average cost of a car in 1975?

The average cost was $5,000. US Census data shows that the median price of new home in the U.S. in November 2014 was$280,900. This was $10,700 more than 14 times the price in November 1964. What was the median price of a new home in November 1964? The median price was$19,300.

Solve Percent Applications

There are several methods to solve percent equations. In algebra, it is easiest if we just translate English sentences into algebraic equations and then solve the equations. Be sure to change the given percent to a decimal before you use it in the equation.

ⓒ 168 is what percent of 112?

| | | | | <: valign=”top”>| Translate into algebra. Let n = the number. | | | | <: valign=”top”>| Multiply. | | | | <: valign=”top”>| | | | 37.8 is 45% of 84. | <: valign=”top”>

| | | | | <: valign=”top”>| Translate. Let n = the amount. | | | | <: valign=”top”>| Multiply. | | | | <: valign=”top”>| Divide both sides by 0.085 and simplify. | | | | <: valign=”top”>| | | | 8.5% of $56 is$4.76 | <: valign=”top”>

 We are asked to find percent, so we must have our result in percent form. Translate into algebra. Let p = the percent. Multiply. Divide both sides by 112 and simplify. Convert to percent. 168 is 150% of 112.

Translate and solve: ⓐ What number is 45% of 80? ⓑ 7.5% of what amount is \$1.95? ⓒ 110 is what percent of 88?