1.2 Problem Solving Strategies
1.2 Problem Solving Strategies
Problem solving is a process of transforming the description of a problem into the solution of that problem by
knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving
strategies, techniques and tools.
Problem solving (within the context of developing programs) refers to analyzing a problem with the intention of
deriving a solution for the problem.
REQUIREMENTS SPECIFICATIONS:
State the problem clearly and unambiguously (Doubtless) to understand exactly:
• What the problem is?
• What is needed to solve it?
• What the solution should provide
• If there are constraints and special conditions.
PROBLEM ANALYSIS:
In the analysis phase, we should identity the following:
• Inputs: To the problem, their form and the input media to be used.
• Outputs: Expected from the problem, their form and the output media to
be used.
• Special constraints or (necessity) conditions (if any).
• Formulas or equations to be used.
Example:
Problem: Compute and display the total cost of apples given the number of kilograms (kg) of apples
purchased and the cost per kg of apples.
• Input: Quantity of Apples purchased (in kg).
• Cost per kg of Apples (in Rs. per kg).
• Output: Total cost of Apples (in Rs.).
• Constraint: N/A
• Formula: Total cost = Cost per kg x Quantity.
DESIGN THE ALGORITHM TO SOLVE THE PROBLEM:
Purpose: To develop and verify algorithm.
An algorithm is a list of steps to be executed with the right order in which these steps should be executed.
An algorithm must satisfy these requirements:
TOP-DOWN DESIGN:
1.List the major steps (most algorithm consists of at least the following):
2. Perform algorithm refinement the step(s) may need to be broken down into a more detailed list of steps.
- It must be correct and it must solve the problem for which it is designed.
- It must execute and terminate in a finite amount of time.
- It must be efficient enough so that it can solve the intended problem using the resource currently
available on the computer.
Example:
PSEUDO CODE:
Pseudo code is semiformal English – like language with limited vocabulary that can be used to design and
describe algorithms.
- Eventually ends
FLOWCHART:
Flowchart is a graph used to depict or show a step by step solution using symbols which represent a task. The
symbols
used consist of geometrical shapes that are connected by flow lines .It is an alternative to pseudo coding, where as a
pseudo code description is verbal. A flowchart is graphical in nature.
The symbols:
Off- page connector: its provide continuation of a logical path on another page.
→ Flow lines: indicate the logical sequence of execution steps in the algorithm.
Any algorithm can be described using only three control program structures:
1. Sequence.
2. Selection.
3. Repetition.
Example:
Begin
Read birthdate
Age=today’s date - birth date
Print age
End
If age>55
Print “ ”
Else
Print “ ”
Endif
If (marks>=60)
Printf(“passed\n”);
Else
Printf(“failed\n);
If else structure:
- specifies a block of one or more statements that are repeatedly executed until
a condition is satisfied
While<termination condition>
Statements
IMPLEMENTATION:
The output of the program must be the solution of the intended problem.
The program testing is the process of executing a program to demonstrate its correctness. Program
verification is the process of ensuring that a program meets user requirement. After the program is compiled
run the program and test/verify it with different inputs before the program can be released to the public or
other users.
Example:
DOCUMENTATION:
It contains details produced at all stages of the program development cycle. It can be done in 2 ways
It is important not only for other people to use or modify the program, but also to understand the own
program after a long time.
*********************************************************************************