Problem Solving Strategies
Computer based problem solving is a systematic process of designing, implementing and using
programming tools during the problem solving stage. This method enables the computer system
to be more intuitive with human logic than machine logic. Final outcome of this process is
software tools which is dedicated to solve the problem under consideration. Software is just a
collection of computer programs and programs are a set of instructions which guides
computer’s hardware. These instructions need to be well specified for solving the problem.
After its creation, the software should be error free and well documented. Software
development is the process of creating such software, which satisfies end user’s requirements
and needs.
Problem Solving Strategies include:
1. Problem Definition/Problem Analysis
2. Program Design - Algorithm, Flowchart and Pseudocode
3. Coding
4. Compilation and Execution
5. Debugging and Testing
6. Program Documentation
1. Problem Definition/Problem Analysis:
Problem analysis is the process of defining a problem and decomposing overall system into
smaller parts to identify possible inputs, processes and outputs associated with the problem.
This task is further subdivided into six subtasks namely:
i. Specifying the Objective:First, we need to know what problem is actually being
solved. Making a clear statement of the problem depends upon the size and complexity
of the problem. Smaller problems not involving multiple subsystems can easily be
stated and then we can move onto the next step of “Program Design”. However, a
problem interacting with various subsystems and series of programs require complex
analysis, in-depth research and careful coordination of people, procedures and
programs.
ii. Specifying the Output : Before identifying inputs required for the system, we need to
identify what comes out of the system. The best way to specify output is to prepare
some output forms and required format for displaying result. The best person to judge
an output form is the end user of the system i.e. the one who uses the software to his
benefit. Various forms can be designed by the programmer which must be examined to
see whether they are useful or not.
iii. Specifying Input Requirements : After having specified the outputs, the input and
data required for the system need to be specified as well. One needs to identify the list
of inputs required and the source of data. For example, in a simple program to keep
student’s record, the inputs could be the student’s name, address, roll-numbers, etc. The
sources could be the students themselves or the person supervising them.
iv. Specifying Processing Requirements : When output and inputs are specified, we need
to specify process that converts specified inputs into desired output. If the proposed
program is to replace or supplement an existing one, a careful evaluation of the present
processing procedures needs to be made, noting any improvements that could made. If
the proposed system is not designed to replace an existing system, then it is well advised
to carefully evaluate another system that addresses a similar problem.
v. Evaluating the Feasibility : After the successful completion of all the above four steps
one needs to see whether the things accomplished so far in the process of problem
solving are practical and feasible. To replace an existing system one needs to determine
how the potential improvements outperforms existing system or other similar system.
vi. Problem Analysis Documentation:Before concluding the program analysis stage, it is
best to record whatever has been done so far in the first phase of program development.
1
The record should contain the statement of program objectives, output and input
specifications, processing requirements and feasibility.
2. Problem Design/Planning the Solution:
The second stage in software development or problem solving using computer cycle is program
design. This stage consists of preparing algorithms, flowcharts and pseudocodes. Generally,
this stage intends to make the program more user friendly, feasible and optimized. Programmer
just requires a pen and pencil in this step in which the tasks are first converted into a structured
layout without the involvement of computer. In structured programming, a given task is divided
into number of sub-tasks which are termed as modules. Each process is further divided until
no further divisions are required. This process of dividing a program into modules and then
into sub-modules is known as “top down” design approach. Dividing a program into modules
(functions) breaks down a given programming task into small, independent and manageable
tasks.
In program design we are mainly interested in designing:
i. Algorithms
ii. Flowcharts
iii. Pseudocodes
3. Coding (Programming)
In this stage, process of writing actual program takes place. A coded program is most popularly
referred to as a source code. The coding process can be done in any language (high level and
low level). The actual use of computer takes place in this stage in which the programmer writes
a sequence of instructions ready for execution. Coding is also known as programming. The
logic algorithm is translated into a programming language such as Visual Basic, JAVA, C++
etc
Good program possess following characteristics :
1. Comment clauses in the program help to make the program readable and
understandable by people other than the original programmer.
2. It should be efficient.
3. It must be reliable enough to work under all reasonable conditions to provide a correct
output.
4. It must be able to detect unreasonable error conditions and report them to the end user
or programmer without crashing the system.
5. It should be easy to maintain and support after installation.
4. Compilation and Execution Process
Generally coding is done in high level language or low level language (assembly language).
For the computer to understand these languages, they must be translated into machine level
language. The translation process is carried out by a compiler/interpreter (for high level
language) or an assembler (for assembly language program). The machine language code thus
created can be saved and run immediately or later on.
In an interpreted program, each program statement is converted into machine code before
program is executed. The execution occurs immediately one statement at a time sequentially.
BASIC is one of the frequently used interpreted language. In contrast to interpreter, a compiler
converts a given source code into object code. Once an object code is obtained, the compiled
programs can be faster and more efficient than interpreted programs.
5. Debugging and Testing
To understand debugging and testing more intuitively, lets first consider learning about
different types of error that occurs while programming.
Error
Error means failure of compilation and execution of the computer program or not getting
expected results after execution. Debugging and testing are systematic process during program
development cycle to avoid errors in the program. Different types of error that we encounter
while programming are listed below :
2
Types of Error:
1. Syntax Error : Syntax error is a violation of programming rules while writing it. A
syntax error does not allow the code to run. Syntax error can be easily detected during
the compilation process using compiler. It occurs as a result of the use of misspelt
keywords, unbalanced parenthesis, incorrect punctuation, missing a comma, or
quotation mark, spelling a variable name incorrectly, missing out a colon or semicolon
at the end of a statement.
2. Logical Error : Logical error occurs when a programmer has applied incorrect logic
for solving problem or left out a programming procedure. When logical error occurs
program executes but fails to produce a correct result. Example: Summing up positive
integers and eventually the result negative, multiplying two numbers instead of adding
them will produce incorrect result.
3. Run Time Error : Run time error occurs during the execution of program. This occurs
while the program is running. Runtime errors are commonly referred to as bugs and are
often found during debugging process. A program crash is a noticeable type of runtime
error since the program unexpectedly quits while running. Attempting to divide by zero,
calling invalid functions, computing the square root of a negative number, floating point
error etc. are examples of runtime error.
Runtime Error vs Logical Error
Run Time Error Logical Error
An error that occurs while running a computer An error in a program that causes it to operate
program incorrectly, but not to terminate abnormally
Causes the program to stop execution or to crash Does not cause the program to stop the execution, but
it will give the wrong output
Can occur due to reasons such as dividing a number Can occur due to wrong use of operators and an
by zero, accessing a memory location that is not inappropriate sequence of instructions
available
Debugging
Debugging is the process of finding errors and removing them from a computer program,
otherwise they will lead to failure of the program. Even after taking full care during program
design and coding, some errors may remain in the program and these errors appear during
compilation or linking or execution. Debugging is generally done by program developer.
Testing
Testing is performed to verify that whether the completed software package functions or works
according to the expectations defined by the requirements. Testing is generally performed by
testing team which repetitively executes program with intent to find error. After testing, list of
errors and related information is sent to program developer or developmentteam.
Debugging vs Testing
Major differences between debugging and testing are pointed below :
i. Debugging is the process of fixing errors while Testing is the process of finding as
many errors as possible.
ii. Debugging is done during program development phase while Testing is done during
testing phase which comes after development phase.
iii. Debugging is done by program developer while Testing is generally carried out by
separate testing team rather than program developer.
iv. Testing can be manual or automated while debugging can only be done manually
v. For Testing, there is no need for design knowledge while debugging cant be done
without the design knowledge
6. Program Documentation
3
The program documentation is the process of collecting information about the program. The
documentation process starts from the problem analysis phase to debugging and testing.
Documentation consists two types of documentation, they are:
1. Programmer's Documentation
2. User's Documentation
Programmer's Documentation
Programmer’s documentation contains all the technical details. Without proper documentation
it is very difficult even for the originl programmer to update and maintain the program. A
programmer’s documentation contains the necessary information that a programmer requires
to update and maintain the program. These information includes:
1. Program analysis document, with a concise statement of program’s objectives, outputs
and processing procedures.
2. Program design documents with appropriate flowcharts and diagrams.
3. Program verification documents for outlining, checking, testing and correction
procedures along with the list of sample data and results.
4. Log used to document future program revision and maintenance activity.
User's Documentation
User documentation is required for the end user who installs and uses the program. It consists
instructions for installation of the program and user manual.
Algorithm, Flowchart and Pseudocode
i. Algorithm: An algorithm is an effective step-by-step procedure for solving a problem in a
finite number of steps. In other words, it is a finite set of well-defined instructions or step-by-
step description of the procedure written in human readable language for solving a given
problem. An algorithm itself is division of a problem into small steps which are ordered in
sequence and easily understandable. Algorithms are very important to the way computers
process information, because a computer program is basically an algorithm that tells computer
what specific tasks to perform in what specific order to accomplish a specific task. The same
problem can be solved with different methods. So, for solving the same problem, different
algorithms can be designed. In these algorithms, number of steps, time and efforts may vary
more or less.
Characteristics/Properties of an Algorithm
1. Finiteness: An algorithm should have finite number of steps and it should end after a
finite time.
2. Input: An algorithm may have many inputs or no inputs at all.
3. Output: It should result at least one output.
4. Definiteness: Each step must be clear, well-defined and precise. There should be no
ambiguity.
5. Effectiveness: Each step must be simple and should take a finite amount of time.
Example of an Algorithm
Example 1: Going home from School : you can go by Bus or Taxi depending on choice/option
Option B: Bus Algorithm
Option A: Taxi Algorithm i. Start
i. Start ii. Walk to the Bus Stand
ii. Go to the Taxi Stand iii. Board a Bus
iii. Get in a Taxi iv. Get off the Closest Bus stop close to
iv. Guide the driver to your home your house
v. Stop v. Walk to your home
vi. Stop
Each algorithm has one purpose but different options. Each depends on factors like cost, time,
security, comfort etc.
4
More example of Algorithm
Problem 1: Find the area of a Circle of radius r.
Inputs to the algorithm: Radius r of the Circle.
Expected output: Area of the Circle
Algorithm:
Step1: Start
Step 2: Read/input the Radius r of the Circle
Step 3: Area = PI*r*r // calculation of area
Step 4: Print Area
Step 5: End
Problem2: Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm:
First num1. Second num2.
Expected output:
Sum of the two numbers.
Algorithm:
Step1: Start
Step2: Read\input the first num1.
Step3: Read\input the second num2.
Step4: Sum = num1+num2 // calculation of sum
Step5: Print Sum
Step6: End
Algorithm : Calculation of Simple Interest
Step 1: Start
Step 2: Read principle (P), time (T) and rate (R)
Step 3: Calculate I = P*T*R/100
Step 4: Print I as Interest
Step 5: Stop
Advantages of an Algorithm
1. Effective Communication: Since algorithm is written in English like language, it is
simple to understand step-by-step solution of the problems.
2. Easy Debugging: Well-designed algorithm makes debugging easy so that we can
identify logical error in the program.
3. Easy and Efficient Coding: An algorithm acts as a blueprint of a program and helps
during program development.
4. Independent of Programming Language: An algorithm is independent of
programming languages and can be easily coded using any high level language.
Disadvantages of an Algorithm
1. Developing algorithm for complex problems would be time consuming and difficult to
understand.
2. Understanding complex logic through algorithms can be very difficult.
ii. Flow Charts:
Flowchart is basically a pictorial or diagrammatic representation of an algorithm using standard
symbols.
In other words, flowchart is a graphical representation that explains the sequence of operations
to be performed in order to solve a problem under consideration
Standard Flowchart Symbols
5
To express different operations in the flowchart various standard symbols are used. All
symbols are connected among themselves in order to show the flow of information and
processing. Different symbols as prescribed by American National Standard Institute
(ANSI) which are frequently required while drawing flowchart are tabulated below:
Figure: Flowchart Symbols
Example of Flowchart
Flowchart example for calculating simple interest is shown below:
Figure: Flowchart for calculating simple interest
Advantages of Flowchart
Drawing flowchart while solving any problem has following advantages:
1. Effective Communication : Flowcharts are better way of communicating the logic of
the system.
2. Effective Analysis : Using flowchart problem can be analyzed more efficiently.
6
3. Easy Debugging and Efficient Testing : The Flowchart helps in debugging and testing
process.
4. Efficient Coding : The flowcharts are very useful during program development phase.
5. Proper Documentation : Flowcharts serves as a good program documentation, which
is needed for various purpose.
6. Efficient Program Maintenance : Maintenance of operating programs becomes easy
with the help of flowchart.
Disadvantages of Flowchart
1. Complex Logic: For complicated logic, flowchart becomes complex and clumsy.
2. Difficulty in Modifications: If change is required in the logic then flowchart needs to
be redrawn and requires a lot of time.
iii. Pseudocodes
Pseudocode is structured English for describing algorithms concisely. It is made up of two
words, namely, pseudo meaning imitation and code meaning instructions. As the name
suggests, pseudocode does not obey the syntax rules of any particular programming language
i.e. it is not a real programming code. It allows the designer to focus on main logic without
being distracted by programming languages syntax.
Guidelines for Preparing Pseudocode
1. Pseudocode will be enclosed by START (or BEGIN) and STOP (or END).
2. Pseudocode should be concise so ignore unnecessary details.
3. To accept data from user, generally used statements are INPUT, READ, GET or
OBTAIN.
4. To display result or any message, generally used statements are PRINT, DISPLAY, or
WRITE.
5. Generally used keywords are capitalized while preparing pseudocode.
Example of Pseudocode
Pseudocode : Calculation of Simple Interest
Step 1: START
Step 2: READ P, T, R
Step 3: I = P*T*R/100
Step 4: PRINT I
Step 5: STOP
Advantages of Pseudocode
1. It allows the designer to focus on main logic without being distracted by programming
languages syntax.
2. Since it is language independent, it can be translated to any computer language code.
3. It allows designer to express logic in plain natural language.
4. It is easier to write actual code using pseudocode.
5. Unlike algorithms, pseudocodes are concise so pseudocodes are more readable and
easier to modify.
Disadvantages of Pseudocode
1. There are no accepted standards for writing pseudocodes and designer use their own
style while writing pseudocodes.
2. Pseudocode cannot be compiled and executed so its correctness cannot be verified by
using computers.
Algorithm vs Pseudocode vs Program:
1. An algorithm is defined as a well-defined sequence of steps that provides a solution for
a given problem, whereas a pseudocode is one of the methods that can be used to
represent an algorithm.
7
2. While algorithms are generally written in a natural language or plain English language,
pseudocode is written in a format that is similar to the structure of a high-level
programming language. Program on the other hand allows us to write a code in a
particular programming language.
So, as depicted above you can clearly see how the algorithm is used to generate the
pseudocode which is further expanded by following a particular syntax of a programming
language to create the code of the program .
Write an Algorithm, Psuedocode and draw a flowchart to calculate area of a rectangle
Algorithm Psuedocode
Step 1: Start Begin
Step 2: Input length and breadth Input length, L
Step 3: area = length * breadth Input Breath B
Step 4: print area Area= L*B
Step 5: stop
Display Area
Stop