Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Problem Solving

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

Introduction

A computer is a programmable machine that receives input, stores and


manipulates data, and provides output in a useful format. Computers are used for
solving various day-to-day problems and thus problem solving is an essential skill
that a student should know. In order that a computer solves a problem, a method
for the solution and a detailed procedure has to be prepared by the programmer.

A computer is a very powerful and versatile machine capable of performing


a multitude of different tasks, yet it has no intelligence or thinking power. The
intelligence Quotient (I.Q) of a computer is zero. A computer performs many tasks
exactly in the same manner as it is told to do. This places responsibility on the
user to instruct the computer in a correct and precise manner, so that the machine is
able to perform the required job in a proper way.

A wrong or ambiguous instruction may sometimes prove disastrous. In


order to instruct a computer correctly, the user must have clear
understanding of the problem to be solved. A part from this he should be able to
develop a method, in the form of series of sequential steps, to solve it. Once the
problem is well-defined and a method of solving it is developed, then instructing
the computer to solve the problem becomes relatively easier task.

Thus, before attempt to write a computer program to solve a given problem.


It is necessary to formulate or define the problem in a precise manner. Once the
problem is defined, the steps required to solve it, must be stated clearly in the
required order.

Problem Solving

Problem solving is the process of identifying a problem, developing an


algorithm for the identified problem and finally implementing the algorithm to
develop a computer program.

Steps in Problem Solving

• Problem Solving is the sequential process of analyzing information related


to a given situation and generating appropriate response options.

• There are 6 steps that you should follow in order to solve a problem:
– 1. Understand the Problem

– 2. Formulate a Model

– 3. Develop an Algorithm

– 4. Write the Program

– 5. Test the Program

– 6. Evaluate the Solution

• When problems are straightforward and easy, we can easily find the
solution. But a complex problem requires a methodical approach to find the
right solution. Problem solving begins with the precise

– identification of the problem and

– ends with a complete working solution

– in terms of a program or software.

1. Understand the problem

• The first step to solving any problem is to make sure that you understand the
problem that you are trying to solve. we should be absolutely sure about the
objectives of the given problem.

• You need to know:

• What input data/information is available ?

• What does it represent ?

• What format is it in ?

• Is anything missing ?

• Do I have everything that I need ?

• What output information am I trying to produce ?


• What do I want the result to look like … text, a picture, a graph … ?

• What am I going to have to compute ?

By analyzing a problem, we would


be able to figure out what are the
inputs that our program should
accept and the outputs that it
should produce.
2. Formulate the model

• Now we need to understand the processing part of the problem. Many


problems break down into smaller problems that require some kind of
simple mathematical computations in order to process the data.

3. Develop an algorithm

• An algorithm is a precise sequence of instructions for solving a problem. To


develop an algorithm, we need to represent the instructions in some way that
is understandable to a person who is trying to figure out the steps involved.

• The commonly used representations for an algorithm is by using

– (1) pseudo code, or

– (2) flow charts.

Pseudo codes

These are the instructions written in ordinary English using mathematical and
logical symbols to display the program logic.

Flow Charts
It is a diagrammatic representation of the sequence of operation for a given
problem.

4. Writing the Program

• In this step needs to transform the algorithm into a set of instructions that
can be understood by the computer. Writing a program is often called
"writing code" or “implementing an algorithm”. So the code (or source
code) is actually the program itself.

After finalizing the algorithm, we need to


convert the algorithm into the format which
can be understood by the computer to
generate the desired solution. Different high
level programming languages can be used for
writing a program.
5. Testing the program

In this step make sure that it solves the problem that it was intended to solve and
that the solutions are correct.

Running a program is the process of


telling the computer to evaluate the
compiled instructions.
• When you run your program, if all is well, you should see the correct output.

• It is possible however, that your program works correctly for some set of
data input but not for all.
• If the output of your program is incorrect, it is possible that you did not
convert your algorithm properly into a proper program.

• It is also possible that you did not produce a proper algorithm back in step 3
that handles all situations that could arise.

problems with your program are known as bugs.

Bugs are problems/errors with a


program that cause it to stop working
or produce incorrect or undesirable
results.

Evaluate the solution

• Once your program produces a result that seems correct, you need to re-
consider the original problem and make sure that the answer is formatted
into a proper solution to the problem.

Algorithm

A set of sequential steps usually written in Ordinary Language to solve a

given problem is called Algorithm. It may be possible to solve to problem in more


than one ways, resulting in more than one algorithm. The choice of various
algorithms depends on the factors like reliability, accuracy and easy to modify. The
most important factor in the choice of algorithm is the time requirement to execute
it, after writing code in High-level language with the help of a computer. The
algorithm which will need the least time when executed is considered the best.

Steps involved in algorithm development


An algorithm can be defined as “a complete, unambiguous, finite number of
logical steps for solving a specific problem “

Step1. Identification of input: For an algorithm, there are quantities to be


supplied called input and these are fed externally. The input is to be indentified
first for any specified problem.

Step2: Identification of output: From an algorithm, at least one quantity is


produced, called for any specified problem.

Step3 : Identification the processing operations : All the calculations to be


performed in order to lead to output from the input are to be identified in an
orderly manner.

Example

1. Suppose we want to find the average of three numbers, the algorithm is as


follows

Step 1 Read the numbers a, b, c

Step 2 Compute the sum of a, b and c

Step 3 Divide the sum by 3

Step 4 Store the result in variable d

Step 5 Print the value of d

Step 6 End of the program

2. Write an algorithm to calculate the simple interest using the formula.

Simple interest = P*N* R/100.

Where P is principle Amount, N is the number of years and R is the rate

of interest.

Step 1: Read the three input quantities’ P, N and R.


Step 2 : Calculate simple interest as

Simple interest = P* N* R/100

Step 3: Print simple interest.

Step 4: Stop

What is flow chart?

• A flowchart is a graphical representation of the problem solving


process.

• A flowchart gives a step-by-step procedure for solution of a problem.

• Various geometrical shaped boxes represent the steps of the solution.

• The boxes are connected by directional arrows to show the flow of the
solution problem solving.

• The main use of a flowchart is to show the sequence of steps and the
flow of a computer program.

• Some of the other uses of a flowchart are to communicate a solution to a


problem, explain a concept, and show the logic of classification of data,
rules and flow of playing a game.

• Terminator

This ellipse symbol represents the beginning and end point in a program. We
use start and stop option in it.

Input/Output Symbol
This parallelogram symbol is used to take any input or output in the
algorithm.

Process Symbol
A rectangle indicates the processing, calculation and arithmetic operations.
Decision Symbol
The diamond is used when we want to take any decision in the program.

Data Flow Symbol    

These arrows are used to display the flow of the program. It shows the path
of logic flow in a program.

Flowcharts can be drawn for a problem solving process using these


three basic structures.
1. Sequence
2. Selection
3. Repitition
Sequence

In a computer program or an algorithm, sequence involves simple steps


which are to be executed one after the other. The steps are executed in
the same order in which they are written.

Task : Write an algorithm to add two numbers.

Step 1 : Start

Step 2 : Read a

Step 3 : Read b

Step 4 : Add a , b

Step 5 : Store in d

Step 6 : Print d

Step 7 : End
Selection

• Selection is used in a computer program or algorithm to determine


which particular step or set of steps is to be executed.

• This is also referred to as a ‘decision’.

• A selection statement can be used to choose a specific path dependent on


a condition.
Repitition

• Repetition allows for a portion of an algorithm or computer program to


be executed any number of times dependent on some condition being
met.

• An occurrence of repetition is usually known as a loop.

• Specifies a block of one or more statements that are repeatedly executed


until a condition is satisfied.

• Usually the loop has two important parts:

• 1. An expression that is tested for a true/false,

• 2. A statement or block that is repeated as long as the expression is true



There are 2 styles of repetition or loop

• 1. Pre-test loop

2. Post test loop

Pre-test

• A pre-tested loop is so named because the condition has to be met at the


very beginning of the loop or the body of the loop is not executed.

• This construct is often called a guarded loop.

• The body of the loop is executed repeatedly while the termination


condition is true.

Post test

• A post-tested loop executes the body of the loop before testing the
termination condition.

• This construct is often referred to as an unguarded loop.


• The body of the loop is repeatedly executed until the termination
condition is true.

You might also like