introduction to problem solving. introductory discussion? what problems are you faced with daily? do...

22
Introduction to problem solving

Upload: reginald-joel-charles

Post on 30-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Introduction

to

problem solving

Page 2: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Introductory Discussion?

What problems are you faced with daily? Do you think a computer

can be designed to solve those problems?

Do you think that the computer is smarter than a human? Discuss.

Page 3: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

The Role of the Computer Programmer

• Computers are designed to solve problems speedily and accurately.

• There is no problem that can be solved by a computer that cannot be solved by humans as well. It is just that it would take considerably longer for humans to solve it and the degree of accuracy would not be the same.

• Although computers are used to solve problems, they do not have brains. They cannot think. They cannot reason, although recent advances in artificial intelligence may seem to suggest otherwise.

• A computer is a moron – it simply does exactly what we tell it to do. This is why the role of the computer programmer is so important.

• There is nothing magical about the way computers solve problems. A computer simply follows (executes) a set of instructions given to it by the programmer and produces the specified results.

Page 4: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

The Role of the Computer Programmer

• The computer programmer creates the instructions for the computer programmer to follow. If the computer produces undesirable results, it is not the computer’s fault; it is the programmer’s fault.

• Consider the following analogy:

The food processor has buttons that indicate the various functions that can be performed – chop, grate, puree, liquefy, and so on. Now suppose you want chop some carrots to make a stew. You place the carrots in the food processor and press the chop button, but instead of chopping the carrots, the food processor purees it. The result is a stew that looks like a mush.

Who would you blame for this undesired result? Would it be the food processor, the designer or yourself (the user)? Discuss

Page 5: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

The Role of the Computer Programmer

• In this case:

The user did what he was supposed to do (that is, press the chop button)

The food processor did what it was supposed to do, that is, it carried out the instructions associated with the chop button.

The designer is at fault here. Clearly the incorrect instructions were linked to the chop button.

• In a similar way, a computer carries out the instructions given to it by the programmer. The programmer must, therefore, ensure that the correct instructions are given at all times, and that the instructions are precise (accurate) and unambiguous (clear).

• Otherwise the results might be undesirable and in some critical situation such as airline navigation, the result could be fatal.

Page 6: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

The Role of the Computer Programmer

CLASS DISCUSSION

1. Why are computers built to solve problems that the human brain can solve?

2. Give some scenarios in which undesirable instructions in a computer can be fatal?

3. How is a computer able to solve problems?

4. A freezer was turned up to level 7 so that items could get well-frozen; the items were defrosted instead. What could be the cause of the error?

Page 7: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

• Instructions are given to the computer in the form of computer programs.

A computer program is a finite set of precise instructions, written in a programming language.

• Before we write a computer program , we first have to find a way to solve the problem at hand. After we have figured out how to solve

the problem, we then translate the solution into a language that is meaningful to the computer.

• Giving instructions to a computer can be challenging at times and require a certain amount of skill. This is because giving precise, unambiguous instructions is not inherent in human nature. Humans tend to make assumptions when giving instructions and they expect other humans to reason things out in order to get to a logical conclusion.

Page 8: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

Consider the following problem:

You would like to give directions to someone to get to the nearest post office starting at point A.

A possible set of instructions might be:

1. Proceed a mile or so down the road until you reach the roundabout.

2. Turn left at the roundabout and follow the road until you see a green house on the right hand-side.

3. The post office is about the 3rd or 4th building on the right after the green house. You’ll see the sign in front, you cant miss it.

CLASS DISCUSSION

DO YOU THINK THE INSTRUCTIONS ARE UNAMBIGUOUS AND PRECISE? What would you change or add to the instructions?

Page 9: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

• To the average person, the above instruction may appear to be clear and straightforward. However, once you start the following instructions, you may find that vital pieces of information may have been omitted and other bits of information might not be as precise as they could have been.

• For example, one might find that there is a junction or a fork in the road before one reaches the roundabout. This vital information was omitted so when the person arrives at the junction he/she would have to make a decision as to which way to proceed. Do I turn right, left or proceed straight ahead? Making the wrong decision could lead to all sorts of consequences.

Page 10: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

Let us carefully assess each instruction:

1. “Proceed a mile or so” is imprecise. How far should the person have to walk or drive before arriving at the roundabout?

2. What if there is more than one green house on the right? The instruction should precisely state whether it is the first, second or third green house that is being referred to.

3. In the third instruction, it might not be difficult for a person to figure out whether or not the post office is the 3rd or 4th building. However, it would be impossible for a computer to execute on instructions written in this form. Computers must be told exactly what they must do in the correct sequence. We call the set of instructions an ALGORITHM.

Page 11: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

ALGORITHMS HAVE FOUR VERY IMPORTANT ATTRIBUTES.

They must be precise

Page 12: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

ALGORITHMS HAVE FOUR VERY IMPORTANT ATTRIBUTES.

They must be precise

They must be

unambiguous

Page 13: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

ALGORITHMS HAVE FOUR VERY IMPORTANT ATTRIBUTES.

They must be precise

They must be

unambiguous

They must be

finite, that is,terminate after

a finite number of steps

Page 14: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

How are instructions given to the Computer?

ALGORITHMS HAVE FOUR VERY IMPORTANT ATTRIBUTES.

They must be precise

They must be

unambiguous

They must be

finite, that is,terminate after

a finite number of steps

The instructions must be in a

logical sequence

Page 15: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

It is important to note that:

Writing a program is simply a formal way of giving instructions to someone (in this case the computer) to perform a particular task. The only difficulty in writing a program is in knowing how to solve the problem.

If you do not know how to get to the post office, you would not be able to give directions to someone. Likewise a programmer must figure out a way to solve the problem before he/she proceeds to tell the computer what it should do.

How are instructions given to the Computer?

Page 16: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

CLASS ACTIVITY

Arrange yourselves in groups of 4 or 5. Write the step by step instructions to solve one of the following everyday problem (10-minute exercise):

1. Write a recipe for making a cheese omelette.

2. Write the instructions to teach your mom how to retrieve voice messages from generic cell phone.

3. Write instructions to give directions to a visitor to get to the Public Hospital from the school premises.

4. Write instructions to tell a novice how to download music from the internet.

5. Write the instructions necessary to determine if an unknown substance contains protein.

6. Write a recipe to make a glass of lemonade.

Note: No more than two groups should work on a particular problem.

The instructions should be written on the board by a group member; the class should discuss the instructions given using the 4 attributes of algorithms to substantiate their suggestions.

Page 17: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

CLASS DISCUSSION

• How are instructions given to a computer?

• Before instructions are given to a computer, what steps should be taken?

• Instructions given to a computer should have 4 important attributes; what are they? Discuss the importance of each attributes using relevant examples.

How are instructions given to the Computer?

Page 18: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Problem-solving on the Computer

2 Major Phases for the design of any computer program

Page 19: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Problem-solving on the Computer

2 Major Phases for the design of any computer program

Problem-Solving Phase

Implementation Phase

Page 20: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Problem-solving on the Computer

2 Major Phases for the design of any computer program

Problem-Solving Phase

Implementation Phase

Step 1: Define the problem

Step 2: Find a solution to the problem

Step 3: Evaluate alternative solutions

Step 4: Represent the most efficient

solution as an algorithm

Step 5: Test the algorithm for

correctness

Page 21: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those

Problem-solving on the Computer

2 Major Phases for the design of any computer program

Problem-Solving Phase

Implementation Phase

Step 1: Define the problem

Step 2: Find a solution to the problem

Step 3: Evaluate alternative solutions

Step 4: Represent the most efficient

solution as an algorithm

Step 5: Test the algorithm for

correctness

Step 1: Translate the algorithm into a

specific programming language.

Step 2: Execute the program on the

computer.

Step 3: Maintain the program

Page 22: Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those