Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

1

PROBLEM-SOLVING
AND
PROGRAM DESIGN
HANDOUT
2

What does problem-solving involves?

T he business dictionary defines problem solving as the process of


working through details of a problem to reach a solution. Problem
solving may include mathematical or systematic operations and can
be a measure of an individual's critical thinking skills.

In our everyday life we actually solve simple problems. For example, you have a problem
meeting your deadlines.

How would you solve this problem?


1. First you need to examine the problem – determine why you are having difficulty meeting
your deadlines.

2. Determine possible solutions to the problem such as: using reminders for the deadlines you
have to meet on your phone, work book etc, get your parents involved in reminding you
about your deadlines, completing the tasks you have to complete as soon as you get them etc.

3. The possible solutions you would then evaluate to determine the best solution to the
problem.

4. Choose the best solution to your problem

Similarly, the computer is designed to solve problems for you


the user. How is this possible? A computer solves end-user
problems by following a set of instructions given to it by the
programmer and produces the specified results.

The computer programmer creates the instructions for the


computer to follow. These instructions are referred to as computer programs. You were
introduced to the term computer programs when we looked at software.

A computer program is a finite set of clear and specific instructions, written in a programming
language.
3

Problem-Solving on the Computer

The design of any computer program involves two major phases:

o The Problem-Solving Phase


o The Implementation Phase

The problem-solving phase is comprised of the following steps:

1) Define the problem


2) Find a solution to the problem
3) Evaluate alternative solutions
4) Represent the most efficient solution as an algorithm (An algorithm may be defined as a
sequence of logical steps used to solve a problem.)
5) Test the algorithm for correctness

Divide and Conquer Approach


Basic treatment of the structured approach for solving complex problems
When we have large problems to solve in the computing world, we apply the divide-and-
conquer concept. The divide-and-conquer approach involves decomposing a large
everyday problem into smaller tasks.

When faced with a complex problem, it is easier to break the problem down into smaller,
more manageable sections and tackle each section as a separate entity, rather than trying to
solve the large problem in one go.
4

Let’s assume you were creating a program to simulate the basic operations of a calculator.
Below is a diagram depicting the divide and conquer concept.

Major Problem:
Performing basic
Calculator
Calculations

Sub_task_1: Sub_task_2: Sub-task_3:


performing Sub-task_4:
Performing Performing
calculations to add Performing
calculations to calculations to
numbers calculations to
subtract numbers multiply numbers divide numbers

Action 1 Action Action 1 Action


Action 1 Action n n n Action 1 Action
n

As you may observe with the diagram above, there is a Major Problem which has been broken
down into four sub-tasks. Each sub-task may have specified action(s) that will be carried out to
solve the overall problem.

Defining the problem

Defining the problem is a way to help the programmer understand what he or she is required to
do. It involves breaking down the problem into three key components:

1. what is given (that is, the inputs)


2. the expected results (that is, the output)
3. the tasks that must be performed (that is, processing)

These three components can be illustrated using what is a called a defining diagram. Some text
may refer to this as the Input Processing and Output (IPO) chart. The defining diagram is a
formal approach to defining a problem. The defining diagram is a table with three columns,
which represents the three components: input, processing and output.
5

INPUT PROCESSING OUTPUT

The Input

The input is the source data provided. You can identify what is the input in a given problem by
the following keywords: given, get, read or accept.

The Output
The output is the end result required. You can identify what is the output in a given problem by
the following keywords: print, display and output.

The Processing

The processing column is a list of what actions are to be performed to achieve the required
output.

Let us look first at a real world scenario. You are learning to bake a cake for the first time. How
would you represent this problem using the defining diagram concept? See the example below.

Defining Diagram:
INPUT PROCESSING OUTPUT
1. Get the ingredients
2. Combine the ingredients The Cake
The Ingredients such as 3. Preheat oven
eggs, butter, flour etc. 4. Place the combine
ingredients in
baking tin
5. Place baking tin in
the preheated oven
6. Leave cake to
bake at the desired temperature

Let us now look at computer related problem.


6

Example 1

A program is required to read two (2) numbers calculate and print their total.
Steps in drawing the defining diagram using the example above.

1. Identify the input (that is, the data that is given). The keyword, read, identifies the input
as two numbers, that is, any two numbers.
2. Identify the output. The keyword, print, identifies the output as the total (or sum) of the
two numbers.
3. List the processing steps. Here, we list all the actions that must be performed in order
to get the desired results. For example: What do we have to do to the two numbers in
order to print their total?
1. We must first get the numbers.
2. We must then calculate their sum.
3. We must then print the total.

See the defining diagram below.

Defining Diagram:
INPUT PROCESSING OUTPUT
1. Read/get 2 numbers
2 Numbers 2. Add numbers together TOTAL
3. Print total

Key things to note:


1. In the defining diagram, the actions must be in a logical sequential order.
2. All the necessary actions must be explicitly stated. For example, the read action and the
print action must not be assumed.
3. The processing section is NOT the solution to the problem. It is simply a list of the
things that must be done in order to solve the problem.

Example 2
Problem 2

A program is required to read three numbers calculate and print their product.
7

Defining Diagram

INPUT PROCESSING OUTPUT


1. Accept 3 numbers

2. Find the product of the three


Three numbers numbers Product
3. Print the product of the three
numbers

PROBLEM SOLVING ACTIVITIES

Activity 1

Outline the steps involved in making an omelette

Possible solution - http://www.wikihow.com/Cook-a-Basic-Omelette


8
9
10
11
12

Activity 2

Write instructions to teach your friend how to turn on a computer and then to access his/her
email.

Possible solution

Step 1: Turn on System unit and Monitor


Step 2: Access Your browser (Internet Explorer or Mozilla Firefox)
Step 3: Locate your email account holder eg. Yahoo or Gmail
Step 4: Type your username and password
Step 5: Click Login

You might also like