Chapter_4
Chapter_4
Problem solving
1. What is problem solving?
Problem solving is the process of identifying a problem, developing
an algorithm and finally implementing the algorithm to develop a
computer program.
3. Algorithm
Algorithm is a set of sequence which followed to solve a problem.
Algorithm for an activity ‘riding a bicycle’:
1) remove the bicycle from the stand,
2) sit on the seat of the bicycle,
3) start peddling,
4) use breaks whenever needed and
5) stop on reaching the destination.
9. Pseudocode
• A pseudocode is another way of representing an algorithm. It is
considered as a non-formal language that helps programmers to write
algorithm. It is a detailed description of instructions that a computer
must follow in a particular order.
• It is intended for human reading and cannot be executed directly by
the computer.
• No specific standard for writing a pseudocode exists.
• The word “pseudo” means “not real,” so “pseudocode” means “not
real code”.
Repetition
Repetitions are used, when we want to do something repeatedly, for a
given number of times.
Pseudocode is as follows:
Step 1: Set count = 0, sum = 0
Step 2: Input num
Step 3: While num is not equal to 0, repeat Steps 4 to 6
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: Input num
Step 7: Compute average = sum/count
Step 8: Print average
15. Coding
Once an algorithm is finalised, it should be coded in a high-level
programming language as selected by the programmer. The ordered set of
instructions are written in that programming language by following its
syntax.
The syntax is the set of rules or grammar that governs the formulation of
the statements in the language, such as spelling, order of words,
punctuation, etc.
Source Code: A program written in a high-level language is called source
code.
We need to translate the source code into machine language using a
compiler or an interpreter so that it can be understood by the computer.
16. Decomposition
Decomposition is a process to ‘decompose’ or break down a complex
problem into smaller subproblems. It is helpful when we have to solve any
big or complex problem.
• Breaking down a complex problem into sub problems also means
that each subproblem can be examined in detail.
• Each subproblem can be solved independently and by different
persons (or teams).
• Having different teams working on different sub-problems can also
be advantageous because specific sub-problems can be assigned to
teams who are experts in solving such problems.
Once the individual sub-problems are solved, it is necessary to test them
for their correctness and integrate them to get the complete solution.
Example:
******************************************************