Chapter no-4
Introduction to Problem Solving
Problem Solving-
It is the process of identifying a problem, developing an algorithm for the identified problem and finally
implementing the algorithm to develop a computer program.
When problems are straightforward and easy, we can easily find the solution. But a complex problem requires a
methodical approach to find the right solution. In other words, we have to apply problem solving techniques.
Problem solving begins with the precise identification of the problem and ends with a complete working solution in
terms of a program or software.
Steps for solving problem-
Key steps required for solving a problem using a computer are as follows-
1. Analysing the problem
2. Developing an algorithm
3. Coding
4. Testing and debugging
1. Analysing the Problem- This step start with read and analyse the problem carefully. By analysing the
problem we would be able to understand what are the inputs available that our program accepts and what
are the output it produces.
2. Developing an algorithm- The logical solution of any problem in English like language is known as algorithm.
In this step we start writing an algorithm of problem until it finds the solution of problem. A problem can
have more than one algorithm and out of them best will be followed.
3. Coding- Coding is a process to transform the selected algorithm into programming language. After finalising
the algorithm, we need to convert the algorithm into program. Different programming languages are used
for this purpose.
4. Testing & Debugging- The program created should be tested on various parameters. The program should
meet the requirements of the user. It must respond within the expected time. It should generate correct
output for all possible inputs. In the presence of syntactical errors, no output will be obtained. 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.
At the last stage program is delivered to user or installed on system where it has to be executed. If still some
post implementations are required then it will be implemented time-to-time.
Algorithm – A step by step solution of any problem to solve a particular task is known algorithm. Algorithms are
always programming language independent and in natural language like English.
Need of Algorithm - The purpose of using an algorithm is to increase the reliability, accuracy and efficiency of
obtaining solutions.
Characteristics of a good algorithm –
Precision — The steps are precisely stated or defined.
Uniqueness — Results of each step are uniquely defined and only depend on the input and the result of the
preceding steps.
Finiteness — The algorithm always stops after a finite number of steps.
Input — The algorithm receives some input.
Output — The algorithm produces some output.
Representation of Algorithm- Once the algorithm is finalized then next step is to represent the algorithm in
visualized form to check the correctness of algorithm. There are two methods to represent the algorithm –
Flowchart
Pseudo code
Either method can be used to represent the algorithm in visualize algorithm
Flow Chart- It is a visualize solution of any program logic or algorithm. It uses various symbols to show the logic of
program. It makes easy to understand the solution of program.
,Sno Symbol Name Meaning
1. Terminal It is used to show the start and stop of program
2. Process Box It is used to show the processing part like calculation
or formula used in the program
3. Decision Box It is used to show the condition. This symbol has two
branches- one is true and other is false
4. Input/Output It is used to show the input and output operations.
Box While performing input operation write input in it
and while performing out write display in it.
5. Connector If your flow chart is too big to fit in one page then
connectors are used to continue it on next page. It is
small circle and any alphabet or number can be
written in it.
6. Flow lines Flow lines are used to show the flow or direction of
program in left, right, up and down direction
Q1. Write an algorithm and draw a flow chart to find the square of any number. Using formula square=num*num
Algorithm-
Step 1. Input a number and store in num Flow Chart- Start
Step 2. Calculate num*num and store in square
Step 3. Print Square
Input num
Square= num*num
Print Square
Stop
Q2. Write an algorithm to calculate the area of circle using formula area= 3.14*r*r. Where r is the radius of circle,
input by the user.
Algorithm- Start
Step 1. Input radius of circle and store in r Flow Chart-
Step 2. Calculate area=3.14*r*r
Input r
Step 3. Print area
area= 3.14*r*r
Print area
Stop
, Pseudocode- A Pseudocode (pronounced Soo-doh-kohd) is another way of representing an algorithm. The word
“pseudo” means “not real,” so “Pseudocode” means “not real code”. Pseudocode is an artificial and informal
language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool.
Following are some of the frequently used keywords while writing Pseudocode:
INPUT
COMPUTE
PRINT
INCREMENT
DECREMENT
IF/ELSE
WHILE
TRUE/FALSE
Q1. Write an algorithm to display the sum of two numbers entered by the user, using both Pseudocode and
flow chart.
Pseudocode – Flow Chart- Start
1. Input num1
2. Input num 2
3. Compute result=num1+num2 Input num1, num2
4. Print result
Result= num1+num2
Print Result
Stop
Q2. Write algorithm to calculate the area and perimeter of rectangle, using both Pseudocode and flow chart
Pseudocode- Flow Chart-
1. Input length
2. Input breadth
3. Compute Area=length * breadth
4. Print Area
5. Computer Perim=2(length +breadth)
6. Print Perim
Introduction to Problem Solving
Problem Solving-
It is the process of identifying a problem, developing an algorithm for the identified problem and finally
implementing the algorithm to develop a computer program.
When problems are straightforward and easy, we can easily find the solution. But a complex problem requires a
methodical approach to find the right solution. In other words, we have to apply problem solving techniques.
Problem solving begins with the precise identification of the problem and ends with a complete working solution in
terms of a program or software.
Steps for solving problem-
Key steps required for solving a problem using a computer are as follows-
1. Analysing the problem
2. Developing an algorithm
3. Coding
4. Testing and debugging
1. Analysing the Problem- This step start with read and analyse the problem carefully. By analysing the
problem we would be able to understand what are the inputs available that our program accepts and what
are the output it produces.
2. Developing an algorithm- The logical solution of any problem in English like language is known as algorithm.
In this step we start writing an algorithm of problem until it finds the solution of problem. A problem can
have more than one algorithm and out of them best will be followed.
3. Coding- Coding is a process to transform the selected algorithm into programming language. After finalising
the algorithm, we need to convert the algorithm into program. Different programming languages are used
for this purpose.
4. Testing & Debugging- The program created should be tested on various parameters. The program should
meet the requirements of the user. It must respond within the expected time. It should generate correct
output for all possible inputs. In the presence of syntactical errors, no output will be obtained. 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.
At the last stage program is delivered to user or installed on system where it has to be executed. If still some
post implementations are required then it will be implemented time-to-time.
Algorithm – A step by step solution of any problem to solve a particular task is known algorithm. Algorithms are
always programming language independent and in natural language like English.
Need of Algorithm - The purpose of using an algorithm is to increase the reliability, accuracy and efficiency of
obtaining solutions.
Characteristics of a good algorithm –
Precision — The steps are precisely stated or defined.
Uniqueness — Results of each step are uniquely defined and only depend on the input and the result of the
preceding steps.
Finiteness — The algorithm always stops after a finite number of steps.
Input — The algorithm receives some input.
Output — The algorithm produces some output.
Representation of Algorithm- Once the algorithm is finalized then next step is to represent the algorithm in
visualized form to check the correctness of algorithm. There are two methods to represent the algorithm –
Flowchart
Pseudo code
Either method can be used to represent the algorithm in visualize algorithm
Flow Chart- It is a visualize solution of any program logic or algorithm. It uses various symbols to show the logic of
program. It makes easy to understand the solution of program.
,Sno Symbol Name Meaning
1. Terminal It is used to show the start and stop of program
2. Process Box It is used to show the processing part like calculation
or formula used in the program
3. Decision Box It is used to show the condition. This symbol has two
branches- one is true and other is false
4. Input/Output It is used to show the input and output operations.
Box While performing input operation write input in it
and while performing out write display in it.
5. Connector If your flow chart is too big to fit in one page then
connectors are used to continue it on next page. It is
small circle and any alphabet or number can be
written in it.
6. Flow lines Flow lines are used to show the flow or direction of
program in left, right, up and down direction
Q1. Write an algorithm and draw a flow chart to find the square of any number. Using formula square=num*num
Algorithm-
Step 1. Input a number and store in num Flow Chart- Start
Step 2. Calculate num*num and store in square
Step 3. Print Square
Input num
Square= num*num
Print Square
Stop
Q2. Write an algorithm to calculate the area of circle using formula area= 3.14*r*r. Where r is the radius of circle,
input by the user.
Algorithm- Start
Step 1. Input radius of circle and store in r Flow Chart-
Step 2. Calculate area=3.14*r*r
Input r
Step 3. Print area
area= 3.14*r*r
Print area
Stop
, Pseudocode- A Pseudocode (pronounced Soo-doh-kohd) is another way of representing an algorithm. The word
“pseudo” means “not real,” so “Pseudocode” means “not real code”. Pseudocode is an artificial and informal
language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool.
Following are some of the frequently used keywords while writing Pseudocode:
INPUT
COMPUTE
INCREMENT
DECREMENT
IF/ELSE
WHILE
TRUE/FALSE
Q1. Write an algorithm to display the sum of two numbers entered by the user, using both Pseudocode and
flow chart.
Pseudocode – Flow Chart- Start
1. Input num1
2. Input num 2
3. Compute result=num1+num2 Input num1, num2
4. Print result
Result= num1+num2
Print Result
Stop
Q2. Write algorithm to calculate the area and perimeter of rectangle, using both Pseudocode and flow chart
Pseudocode- Flow Chart-
1. Input length
2. Input breadth
3. Compute Area=length * breadth
4. Print Area
5. Computer Perim=2(length +breadth)
6. Print Perim