0% found this document useful (0 votes)
2 views

Problem Solving

Uploaded by

buddyquestyt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Problem Solving

Uploaded by

buddyquestyt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction to Problem Solving

Introduction
Learning to write computer program is very much like learning any skill. First, we should understand
the problems well and then try to solve it in a logical manner. For example: We have read many books
available in the market for describing the car driving methods. However, we can learn driving once
we actually get into the car and start driving it. The same logic is applied in computer programming
also. Computer programming is the process of writing, testing, troubleshooting, debugging and
maintaining of a computer program.
An effective program is that which gives result of all different inputs, including wrong input also.
While creating program, we need to follow certain systematic approach. This systematic approach
comprises two steps/things, viz., program structure and program presentation. The program structure
is implemented by using top-down or bottom-up approach and is known as “popular approach‟, while
the program representation plays an important role in making the program more readable and
understandable.
What is a Good Program?
A Good Program means that it should produce correct and faster results, taking into account all the
memory constraints. While making good program, we need to follow certain guidelines of
programming language for creating a successful program.
Problem solving methodology
As we all know, there are many methods/approaches available to solve a particular problem.
However, the efficient way is to adopt a systematic method of problem solving. The use of systematic
method of problem solving is crucial when we use a computer to solve a problem. We introduce here
a seven steps problem solving method, which is closely related to the software life cycle (the various
stages in the life of a program), that can be adapted by each person to solve the problem in their own
style. They are given as under:
1. Problem Definition
2. Problem Analysis
3. Design the problem
4. Coding
5. Program Testing and Debugging
6. Documentation
7. Program Maintenance

Problem Definition/Specification (Theme)


Computer programs are written to solve problems posed by humankind. Prior to writing a program,
one has to understand a description of the problem to solve. This description may be very precise or
vague, but nevertheless, it is necessary/present. For instance, if you want to write a program to “Find
the average of five numbers”, you should ask yourself:
“What does average mean exactly?”
“How to calculate average value?”
Posing such questions compels you to define the problem very precisely. Once you are sure of what
the problem entails, you must write down a list of specifications.
Specifications are precise definitions of what the program must do. It must include the
following at least:
Input: what data must be included as input and in which form?
Output: what data must the program produce and in which form? (in order to solve the problem)
Problem Analysis
In this step, the problem has to be fragmented into smaller and manageable parts. The original
problem has to be analyzed and divided into a number of sub-problems as these sub-problems are
easier to solve and their solutions would become the components of the final program. Each sub-
problem is divided into further smaller ones and this fragmentation has to be continued to achieve
simple solutions.
Designing the problem
Designing the problem can be expressed in the form of
Algorithm
Flowchart
Algorithm: An algorithm is a set of instructions that describe a method for solving a problem. It is
normally given in mix of computer code and English language. This is often called “pseudo-code‟.
Flowchart: The algorithm is represented in the form of a diagram with action boxes linked by lines
showing the order in which they are executed. This is known as “the flow of control‟. It is the
diagrammatic representation of an algorithm.
Coding
The process of translating the algorithm into syntax of a given language is known as “Coding‟. Since
algorithm cannot be executed directly by the computer, it has to be translated into a programming
language.
Program Testing and Debugging
Program Testing means running the program, executing all its instructions/ functions and testing the
logic by entering sample data in order to check the output. Debugging is the process of finding and
correcting the errors in the program code.
Documentation
The documentation includes the problem definition, design documents, a description of the test
perform, a history of the program development and its different versions and a user’s manual. Such a
manual is designed for a naive user and illustrates the preparation of input data, running the program
and obtaining & interpreting the results.
Program maintenance
It is not directly part of the original implementation process, but needs special emphasis. All activities
that occur after a program operation are part of the program maintenance. Many large programs have
long life span that often exceed the lifetime of the hardware they run on. Usually, the expenditure for
the program maintenance will be more than the developmental cost of the program. The program
maintenance includes the following:
Finding and eliminating previously undetected program errors;
Modifying the current program, often to improve its performance, or to adapt to new laws or
government regulations, or to adapt to a new hardware, or to a new operating system;
Adding new features or a better user interface, or new capabilities to the program;
And Updating the documentation.
Algorithms and Flow Charts
Algorithm is a step-by-step process of solving a well-defined computational problem. In practice, in
order to solve any complex real life problems, first we have to define the problem and then, design
algorithm to solve it. Writing and executing a simple program may be easy; however, for executing a
bigger one, each part of the program must be well organized. In short, algorithms are used to simplify
the program implementation. The next step is making the flowchart. It is a type of diagram that
represents an algorithm or process, showing the steps as “boxes‟ of various kinds and their order by
connecting them with arrows. Then, the flowchart will be converted into program code.

Example
Let us take one simple day-to-day example by writing algorithm for making “Maggi Noodles‟ as a
food.
Step 1: Start
Step 2: Take pan with water
Step 3: Put pan on the burner
Step 4: Switch on the gas/burner
Step 5: Put maggi and masala
Step 6: Give two minutes to boil
Step 7: Take off the pan
Step 8: Take out the maggi with the help of fork/spoon
Step 9: Put the maggi on the plate and serve it
Step 10: Stop.
Further, the way of execution of the program shall be categorized into three ways: (i) sequence
statements; (ii) selection statements; and (iii) iteration or looping statements. This is also called as
“control structure‟.
Sequence statements: In this program, all the instructions are executed one after another. Just as in
the above case.
Example
Write an algorithm to find area of a rectangle.
Step 1: Start
Step 2: Take length and breadth and store them as L and B?
Step 3: Multiply by L and B and store it in area
Step 4: Print area
Step 5: Stop
Selective Statements: In this program, some portion of the program is executed based upon the
conditional test. If the conditional test is true, compiler will execute some part of the program,
otherwise it will execute the other part of the program.
Example
Write an algorithm to check whether given number is +ve, -ve or zero.
Step 1: Start
Step 2: Take any number and store it in n.
Step 3: Check n value, if n > 0 then go to step 5 else go to step 4
Step 4: Check n value, if n < 0 then go to step 6 else go to step 7
Step 5: Print “Given number is +ve” and go to step 8
Step 6: Print “Given number is -ve” and go to step 8
Step 7: Print “Given number is zero”
Step 8: Stop
Iterative statements: In some programs, certain set of statements are executed again and again based
upon conditional test. i.e. executed more than one time. This type of execution is called “looping or
iteration‟.
Example
Write an algorithm to print all natural numbers up to “n‟.
Step 1: Start
Step 2: Take any number and store it in n. =5
Step 3: Store 1 in I I=1
Step 4: Check I value, if I<=n then go to step 5 else go to step 8
Step 5: Print I (1 2 3 4 5)
Step 6: Increment I value by 1 I=1+1=2 =3=4=5=6
Step 5: Go to step 4
Step 8: Stop

Flowchart
In the previous section, we have learnt to write algorithms, i.e. step-by step process of solving a
problem. We can also show these steps in graphical form by using some symbols. This is called
flowcharting.
Flowchart Symbols
Some of the standard symbols along with respective function(s) that are used for making flowchart are
as follows:
Example
Draw a flowchart to find bigger number among two numbers (selective)
Solution:

You might also like