6. Introduction to Problem Solving
6. Introduction to Problem Solving
com
2 Problem Analysis
3 Algorithms
5 Pseudocode
7 Example 2: Write an algorithm and draw the flowchart for finding the average
of two numbers
8 Example 3: To check greatest of two numbers
14 Documentation
Page 1 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Requirements specifications
Problem analysis.
Design the algorithm to solve
the problem.
Implementation.
Testing and verification.
Documentation.
Page 2 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
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:
It is important to clearly understand a problem before we begin to find
the solution for it. 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.
Algorithms:
An algorithm is a precise specification of a sequence of instructions
to be carried out in order to solve a given problem.
An Algorithm is a technique to solve a given problem systematically.
An Algorithm is a step-by-step approach to solve a given problem in
finite number of steps.
It takes a set of input values and processes it and gives the output.
Each instruction tells what task is to be performed.
It should be simple.
It may accept zero or more inputs.
It should be precise with no ambiguity.
It should have finite number of steps.
It should produce at least one output.
Disadvantages of an Algorithm:
Page 6 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Flowcharts Symbols:
Symbol Name Function
Page 8 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Drawbacks of flowchart:
(i) Complex logic: For complicated logic the flowchart becomes
complex and clumsy.
(ii) Alterations and modifications: if there is a change in the
logic, the flowchart has to be completely rewritten and
requires lot of time.
(iii) Reproduction: in the case of any problem, reproduction of
flowchart becomes problem since the flowchart symbols
cannot be typed.
Pseudocode
Pseudocode is a simplified, half-English, half-code outline of a
computer program.
This code is written for human understanding rather than computer
or machine understanding.
The aim is to get the idea quickly and also easy to read without
details.
It is like a young child putting sentences together without any
grammar.
Page 9 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
INPUT/READ DECREMENT
COMPUTE IF/ELSE
PRINT WHILE
INCREMENT TRUE/FALSE
Page 10 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Example 2: Write an algorithm and draw the flowchart for finding the
average of two numbers
Algorithm flowchart Pesudocode
Average = sum/2
Output
Average
END
Page 11 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Step 1: get Base (2), Power (4) READ Base (2), Power (4)
END
Page 12 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Page 13 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Pseudocode is as follows:
Page 14 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Coding:
In this stage the algorithm is translated into the program called
source code using some programming language.
Different high level programming languages can be used for
writing a program.
The output of the program must be the solution of the intended
problem.
Testing and Debugging
Testing is the process of finding errors in a program and debugging
is of correcting the errors.
It must respond within the expected time.
It should generate correct output for all possible inputs.
In case the output generated is incorrect, then the program should
be checked for logical errors, if any.
The errors or defects found in the testing phases are debugged or
rectified and the program is again tested. This continues till all the
errors are removed from the program.
Once the software application has been developed, tested and
delivered to the user.
Page 15 of 16
Unit I: Computational Thinking and Programming - 1 Visit to website: learnpython4cbse.com
Documentation
Documentation referrers to written descriptions specification, design
code and comments, internal and external to program which makes
more readable and understandable
Uses of documentation:
Page 16 of 16