Introduction to Problem Solving
Chapter 01 : Computer Science
Program Logic Development Tools
Before developing a solution for any problem in terms of program, you
should read and analyse the given problem and decide about basic sub –
tasks needed to solve a program and the order of these sub tasks. In other
words, you figure out the algorithm for the solution of a given problem
and represent it through various logic development tools
Algorithm Flowchart Pseudocode Decision Tree
Page 2
Program Logic Development Tools
Algorithm
An algorithm is simply a set of steps
used to complete a specific task.
They're the building blocks for
programming, and they allow things
like computers, smartphones, and
websites to function and make
decisions.
Page 3
Program Logic Development Tools
Algorithm
Let's say you want to make some
spaghetti. In order to do this
successfully, there's a certain set of
steps you need to follow in a particular
order.
First, you'll need to boil a pot of water.
Once it's boiling, you then add the
spaghetti and cook it for a set amount
of time, stirring occasionally. Once it's
finished, you drain the water, then it's
ready to be served with a sauce of
your choice.
Page 4
Program Logic Development Tools
Algorithm
This entire process is actually an algorithm. Because you followed these
steps in a particular order, you reached your desired outcome. Programs
work in a similar way. Their code is made up of algorithms telling them
what to do.
Page 5
Program Logic Development Tools
Algorithm
Let us first take an example of a real-
life situation for creating algorithm.
Here is the algorithm for going to the
market to purchase a pen.
Page 6
Program Logic Development Tools
Algorithm
1. Start
2. Get dressed to go the market.
3. Check your wallet for money.
4. If there is no money in the wallet, replenish it.
5. Go to the shop.
6. Ask for your favorite brand of pen.
7. If pen is not available, go to step 7 else go to step 10
8. Give money to the shopkeeper.
9. Keep the purchased pen safely. 9. Go back home.
10. Ask for any other brand of pen.
11. Go to Step 7.
12. Stop
Page 7
Program Logic Development Tools
Algorithm
Let us now create an algorithm to
check whether a number is positive or
negative.
Page 8
Program Logic Development Tools
Algorithm
1. Start
2. Print "Give any number"
3. Read num
4. if (num>0) then print "You entered a positive number"
5. if (num<0) then print "You entered a negative number“
6. else print "You entered Zero“
7. stop
Page 9
Program Logic Development Tools
Algorithm
1. Write an algorithm to calculate area of triangle.
2. Write and algorithm to calculate area of triangle.
3. Write the algorithm to find the maximum of two
numbers.
4. Write the algorithm to find the maximum of three
numbers.
5. Write the algorithm to accept 5 subject marks. calculate
total, percentage and display it on screen.
6. Write the algorithm to find the commission on a
salesman's total sales. The commission on a salesman's
total sales is as follows: If sales < 100 then there is no
commission. If 100 >= sales <= 500 then commission=
Page 10
Program Logic Development Tools
Algorithm
10% of [Link] sales > 500 then commission = 100 + 8%
sales above 500.
7. Write an algorithm to input basic salary of an employee
and calculate its gross salary according to following:
Basic salary <= 10000 : HRA = 20% , DA = 80 %Basic
salary <= 20000 : HRA = 25% , DA = 90 %Basic salary >
20000 : HRA = 30% , DA = 95 %Gross salary = Basic
salary + HRA + DA
8. Write an algorithm to input a number and display the
addition of all the values between 1 and entered
number.
9. Write an algorithm to input one number and display its
Page 11
Program Logic Development Tools
Algorithm
multiplication table.
10. Write an algorithm to calculate total bill for an
electricity company. The electricity company unit
charges and calculate total electricity bill according to
the given conditions: For the first 50 units Rs. 0.50 /
unit. For the next 100 units Rs. 0.75 / unit. For the next
100 units Rs. 1.20 / unit. For unit above 250 Rs. 1.50 /
unit.
11. Write an algorithm to accept one number and print
following: Ex: If input is 5 then output should be -5, -4. -
3, -2. -1, 0 1, 2, 3, 4, 5.
Page 12
Program Logic Development Tools
Algorithm
12. Write an algorithm to input one number and print
following: Ex: If input is 5 then output should 1, 4, 9, 16,
25.
Page 13
Program Logic Development Tools
Flowchart
A flowchart is a diagram that depicts a
process, system or computer
algorithm. They are widely used in
multiple fields to document, study,
plan, improve and communicate often
complex processes in clear, easy-to-
understand diagrams.
Its is also called a graphical
representation of algorithm
Page 14
Program Logic Development Tools
Flowchart Symbols
A flowchart consist of some
predefined symbols (shapes), where
each symbol represent some
predefined operation.
These symbols includes ellipse,
rectangle, parallelogram, diamond and
flow lines.
Page 15
Program Logic Development Tools
Sr No Name Description Symbol or
Shape
1 Start or Stop Also known as the “Terminator Symbol,” this
symbol represents the start points, end
points, and potential outcomes of a path.
Often contains “Start” or “End” within the
shape.
2 Input or Also referred to as the “Data Symbol,” this
Output shape represents data that is available for
input or output as well as representing
resources used or generated. While the
paper tape symbol also represents
input/output, it is outdated and no longer in
common use for flowchart diagramming.
Page 16
Program Logic Development Tools
Sr No Name Description Symbol or
Shape
3 Process Also known as an “Action Symbol,” this shape
represents a process, action, or function. It’s
the most widely-used symbol in flowcharting.
4 Decision Indicates a question to be answered —
usually yes/no or true/false. The flowchart
path may then split off into different
branches depending on the answer or
consequences thereafter.
5 Flow Lines Also called arrow lines. Shows you the flow
of the program. The flow lines can be used
for any direction as up, down, left and right.
Page 17
Program Logic Development Tools
Page 18
Program Logic Development Tools
Flowchart
1. Draw a flowchart to calculate area of triangle.
2. Draw a flowchart to calculate area of triangle.
3. Draw a flowchart to find the maximum of two numbers.
4. Draw a flowchart to find the maximum of three
numbers.
5. Draw a flowchart to accept 5 subject marks. calculate
total, percentage and display it on screen.
6. Draw a flowchart to find the commission on a
salesman's total sales. The commission on a salesman's
total sales is as follows: If sales < 100 then there is no
commission. If 100 >= sales <= 500 then commission=
Page 19
Program Logic Development Tools
Flowchart
10% of [Link] sales > 500 then commission = 100 + 8%
sales above 500.
7. Draw a flowchart to input basic salary of an employee
and calculate its gross salary according to following:
Basic salary <= 10000 : HRA = 20% , DA = 80 %Basic
salary <= 20000 : HRA = 25% , DA = 90 %Basic salary >
20000 : HRA = 30% , DA = 95 %Gross salary = Basic
salary + HRA + DA
8. Draw a flowchart to input a number and display the
addition of all the values between 1 and entered
number.
9. Draw a flowchart to input one number and display its
Page 20
Program Logic Development Tools
Flowchart
multiplication table.
10. Draw a flowchart to calculate total bill for an electricity
company. The electricity company unit charges and
calculate total electricity bill according to the given
conditions: For the first 50 units Rs. 0.50 / unit. For the
next 100 units Rs. 0.75 / unit. For the next 100 units Rs.
1.20 / unit. For unit above 250 Rs. 1.50 / unit.
11. Draw a flowchart to accept one number and print
following: Ex: If input is 5 then output should be -5, -4. -
3, -2. -1, 0 1, 2, 3, 4, 5.
Page 21
Program Logic Development Tools
Flowchart
12. Draw a flowchart to input one number and print
following: Ex: If input is 5 then output should 1, 4, 9, 16,
25.
Page 22
Program Logic Development Tools
Pseudocode
In computer science, pseudocode is a
description of the steps in an
algorithm using a mix of conventions
of programming languages (like
assignment operator, conditional
operator, loop) with informal, usually
self-explanatory, notation of actions
and conditions.
Page 23
Program Logic Development Tools
Page 24
Program Logic Development Tools
Decision Tree
Decision Trees are the way of
presenting rules in hierarchical and
sequential structure, where based on
the hierarchy of rules, certain
outcomes are predicted.
Consider following decision tree.
Page 25
Program Logic Development Tools
Decision Tree
Page 26
Program Logic Development Tools
Decision Tree
Page 27
Program Logic Development Tools
Decision Tree
1. Design a decision tree to represent salesman
commission on a salesman's total sales
The commission on a salesman’s total sales is as
follows:
If sales <100, then there is no commission.
If 100>= sales <=500, then commission = 10% of
sales.
If sales > 500, then commission = 100+8% of sales
above 500
Page 28
Program Logic Development Tools
Decision Tree
2. Design a decision tree to represent HRA, DA of an
employee according to following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary > 20000: HRA = 30%, DA = 95%
Page 29
Program Logic Development Tools
Decision Tree
3. Design a decision tree to determine per unit charges
according to the given conditions:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
<= 500 then commission=
Page 30