Introduction To Problem Solving: Vinod Kumar Verma, PGT (CS), KV Oef Kanpur & Saching Bhardwaj, PGT (CS), KV No.1 Tezpur
Introduction To Problem Solving: Vinod Kumar Verma, PGT (CS), KV Oef Kanpur & Saching Bhardwaj, PGT (CS), KV No.1 Tezpur
Introduction To Problem Solving: Vinod Kumar Verma, PGT (CS), KV Oef Kanpur & Saching Bhardwaj, PGT (CS), KV No.1 Tezpur
com
REQUIREMENTS
ANALYSIS
DESIGN
CODING
TESTING
IMPLEMENTATION
DOCUMENTATION
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
REQUIREMENTS
What the problem is?
What is needed to solve it?
What the solution should provide
If there are constraints and special
conditions?
ANALYSIS
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
DESIGN
In Design phase, we design the proposed
solution without writing a computer
program by using the techniques:
◦ Algorithm
◦ Pseudocode
◦ Flow Chart
Coding
It is the process of transforming design
(Algorithm, Pseudocode, Flow Chart) in a
computer program using any
programming language.
The output of program must be the
solution of intended problem.
Testing
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 we must run
the program and test/verify it with different
inputs before the program can be released
to the public or other users (or to the
instructor of this class)
Implementation
It is the process of installing the software
developed on customer‟s site.
Installation may be done by replace the
entire manual work with the software
developed or in a pilot mode i.e. running
the manual and automated system in
parallel or installing only a part module
with manual work.
It also involves training of software to the
intended users.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
Documentation
- Contains details produced at all stages of the
program development cycle.
Can be done in 2 ways
* writing comments between your line of
codes.
* Creating a separate text file to explain the
program.
- Important not only for other people to use or
modify your program, but also for you to
understand your own program after along time.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
Just a minute…
Write an algorithm to accept two numbers, divide the
first number by the second, and display their quotient.
Allocated time to solve the problem is 05 minutes.
Solution - 1
1. Start the algorithm.
2. Get the first number.
3. Get the second number.
4. Divide the first number by the
second.
5. Display the quotient.
6. End the algorithm. 72 9
72 9 8
Solution - 2
1. Start the algorithm.
2. Get the distance in kilometers.
3. Multiply the distance by 1000.
4. Display the result of
multiplication as distance
in meters. 50
5. End the algorithm.
50 1000 50000
Solution - 3
1. Start the algorithm. 3
2. Get the first number. 1
3. Get the second number.
6 20
4. Get the third number.
2
5. Get the fourth number.
6. Get the fifth number. 8
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
ADVANTAGES
It helps in analyzing the problems effectively.
It acts as a guide during the program development phase.
It help easy debugging of logical errors
DISADVANTAGES
A lengthy flowchart may extend over multiple pages, which reduces
readability.
Drawing a flowchart is time consuming.
The changes made to a single step may cause redrawing the entire
flowchart
Flowchart Symbols
Flowchart Symbols
Start
Accept a
number
Display the
number
Stop
Start
Accept a number
Stop
Just a Minute…
Write a flow chart to calculate area of
rectangle
◦ Allotted Time: 05 minutes
Write a flow chart to enter any number
and check it is divisible by 7 or not
◦ Allotted Time: 05 minutes
Solution - 1
Start
Accept length,
breadth
Display Area
Stop
Solution - 2
Start
Accept a number
No
Display
Is the remainder ‘Number not
equal to zero ? divisible by
Yes 7’
Display ‘Number
divisible by 7’
Stop
Pseudocode
It is a formal way of writing the program logic
whereas algorithm is an informal way of writing
program logic
It is detailed yet easy description of what algorithm
must do.
It is written in formally styled-English language
It is used as an initial step in the process of
developing of program
Provide detailed template to programmers.
It is language independent i.e. it can be converted
to program by using any programming language.
Pseudocode
In Pseudocode we can use few special
words for determining the actions like
◦ Accept/input
◦ Display/print
◦ If / else
◦ Repeat
◦ Start
◦ End
◦ Goto
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
Sequential
A series of steps or statements that are executed
in a specific order.
The beginning and end of a block of statements
can be optionally marked with the keywords
begin & end.
Example:
1. Statement1
2. Statement 2
3. Statement 3
4. .
5. Statement n
Here each statement will be executed one by one
Selection
It determine two course of action depending
upon the condition.
A condition is given here, which will result in
either True(1) or False (0)
The keyword either if and else ( almost all
programming language also support this
keyword )
It is also known as branching statement, because
it provide two branch, one for True and another
for False. Branching will be done depending
upon the condition.
Iteration
It specifies block of one or more statement that
are repeatedly executed till condition remains
true.
Keyword used are :
◦ While (supported by almost all programming language
also)
◦ If with go to (in Pseudocode only)
Iteration consists of 3 main parts:
1. Initial value (from where iteration begins)
2. Condition (upto what condition iteration will continues)
3. Stepping (Increment/Decrement from Initial value to
reach to condition)
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
4. PRINT A
5. A =A + 1 [INCREMENT]
6. END
3. PRINT A
4. A =A + 1
5. IF A<=100 THEN GO TO STEP 3
6. END
Just a Minute….
1. Write a Pseudocode to convert temperature
in Fahrenheit to Celsius
2. Write a Pseudocode to input age and check
age is teenager or not
3. Write a Pseudocode to print all the even
numbers from 2 to 100
4. Write a Pseudocode to print all the odd
numbers from 100 to 1
Decomposition
Large program can be tackled with “divide and
conquer”.
Decomposition happens when we break
down a problem into smaller parts so we can
both understand and manage
the problem better.
For large, complex problems – we can then
analyze, solve and design the smaller parts of
the problem and then put it all together for a
solution.
Advantages
Different people can work on different subprograms.
Parallelization may be possible
Maintenance is easier
Disadvantages
The solution to subprogram might not combine to solve
the original problem
Poorly understood problems are hard to decompose
Need of Decomposition
As studied earlier, first need of decomposition is
to divide the large program into smaller and
manageable sub program, it is easier to write 2
programs of 400 lines than writing single
program of 800 lines.
Each subprogram can be managed
independently
Global changes can be applied very easily
Code can be reused
Functions, modules, class are some example of
decomposition.
VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR &
SACHING BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
for more updates visit: www.python4csip.com
Decomposition Example - 1
Decomposition Example - 2
LIBRARY MANAGEMENT
DELETE DELETE
Decomposition Example - 3
Think of a company creating a mobile phone.
Mobile phones are made up of lots of different
parts. Companies who make phones might
make a list of everything they need and
decompose the manufacturing process so that
one factory can be making the screens while
another makes batteries, another makes the
phone case and another makes mother board.