0% found this document useful (0 votes)
7 views44 pages

Problem Solving & Algorithm

The document outlines the problem-solving cycle, emphasizing the importance of defining and analyzing the problem before developing algorithms and flowcharts. It details the coding process, testing and debugging methods, and the implementation and maintenance phases of software development. Additionally, it provides examples of algorithms for various tasks, illustrating the structured approach to problem-solving.

Uploaded by

isharaadweta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views44 pages

Problem Solving & Algorithm

The document outlines the problem-solving cycle, emphasizing the importance of defining and analyzing the problem before developing algorithms and flowcharts. It details the coding process, testing and debugging methods, and the implementation and maintenance phases of software development. Additionally, it provides examples of algorithms for various tasks, illustrating the structured approach to problem-solving.

Uploaded by

isharaadweta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION

TO
PROBLEM SOLVING
WHAT IS PROBLEM SOLVING ?
PROBLEM
SOLVING CYCLE
We need to understand the
problem statement, what is
1. PROBLEM
our requirement, what
DEFINITION
should be the outcome of the
problem solution
• Problem – Create an App for School

• Requirement – it has to work

• What the problem is ?


• What is needed to solve it ?
• What the solution should provide ?
• If there are constraints & special
conditional ?
• We need to analyse and understand
the problem well before solving, as
inadequate analysis of a problem
may cause the solution to be
insufficient.

2. PROBLEM • As part of problem analysis, we


ANALYSIS break down the problem into smaller
pieces that are easy to solve

• By breaking down the problem we


can also identify all the input and
output variables.
App

Exam Circulars Personal


3. ALGORITHM & FLOWCHARTS

• The term 'Algorithm' refers to a sequence of instructions that must


be followed to solve a problem.

• A programmer must find the best way to solve the problem and
then convert the selected algorithm into instructions in any
programming language.

• The algorithm must terminate after a finite number of steps


3. ALGORITHM & FLOWCHARTS

• A flowchart is a picture (graphical representation) of a


problem-solving process.

• A flowchart gives a step-by-step procedure for solution of a


problem.
4. CODING & DOCUMENTATION

• An act of transforming operations in


each box of the flowchart in terms of
the statement of the program

• The code written using any


programming language ( eg: Python)
is also known as source code
4. CODING & DOCUMENTATION
EXAMPLE:
5. TESTING & DEBUGGING

• Program Testing is the process of executing a program


that demonstrate its correctness.
• We test the program whether it is solving the problem
for various input data values or not.
• We also test whether it is providing the desired output
or not.
• Program verification is a process of ensuring that a
program meets user requirement.
5. TESTING & DEBUGGING
• A Bug is an error in the code.
• Different types of errors:
Syntax errors
Semantic errors
Logical errors
Run time errors
• Debugging is a process of
searching and removing bugs
from the code.
SYNTAX ERROR
SEMANTIC ERROR
LOGICAL ERROR
A logical error is a mistake in reasoning by the
programmer, but it is not a mistake in the
programming language.
An example of a logical error would be dividing by
2.54 instead of multiplying to convert inches to
centimeters
RUN TIME ERROR
6. IMPLEMENTATION & MAINTENANCE
6. IMPLEMENTATION & MAINTENANCE

• During this phase, the program is actively used by the users.

• If the user encounters any problem or wants any enhancement,


then we need to repeat all the phases from the starting, so that
the encountered problem is solved, or enhancement is added.
• The term 'Algorithm' refers to a
ALGORITH sequence of instructions that must be
followed to solve a problem.
M
Write an algorithm to find area and perimeter
of a rectangle.

Step 1: Start
Step 2: Input length, breadth, say L, B
Step 3: Area LXB
Step 4: Perimeter 2X(L+B)
Step 5: Print Area, Perimeter
Step 6: Stop
Write an algorithm to convert temperature from
Celsius to Fahrenheit and vice-versa.
C = ( F – 32 ) * 5 / 9
F = ( C * 9 / 5 ) + 32
Write an algorithm to calculate 24

Step 1: Start
Step 2: Input base (2)
Step 3: Ans base X base X base X base
Step 4: Print Ans
Step 5: Stop
Alternate method

Write an algorithm to calculate 24


Step 1: Start
Step 2: Input Base (2)
Step 3: Product Base
Step 4: Product Product * Base
Step 5: Product Product * Base
Step 6: Product Product * Base
Step 7: Print Product
Step 8: Stop
Step 1: Start
Step 2: Read the distance (in km), k
Step 3: M = k X 1000
Step 4: Display M (in meters)
Step 5: Stop
Write an algorithm to determine the largest of
two numbers.

Step 1: Start
Step 2: Input A, B
Step 3: if A > B then print A else print B
Step 4: Stop
Write an algorithm to accept 5 numbers, find the sum and average

Step 1: Start
Step 2: Read five numbers a, b, c, d, e
Step 3: sum = a + b + c + d + e
Step 4: avg = sum / 5
Step 5: Display sum, avg
Step 6: Stop
Write an algorithm to find the Simple Interest
SI=PxRxT
100
Step 1: Start
Step 2: Read principle, P
Step 3: Read time, T
Step 4: Read rate of interest, R
Step 5: SI = ( P X R X T ) / 100
Step 6: Print SI
Step 7: Stop
Write an algorithm to check whether a given number
is even or odd.

Step 1: Start
Step 2: Input N
Step 3: if N % 2 == 0 then print N is even else
print N is odd
Step 4: Stop
Alternate Method:
Write an algorithm to check whether a given number is even
or odd.

Step 1: Start
Step 2: Input N
Step 3: If N % 2 == 0 then print N is even
Step 4: Else print N is odd
Step 5: Stop
Write an algorithm to classify numbers as “single digit”,
“Double digit” Or “Big”.

Step 1: Start
Step 2: Input N
Step 3: If N <= 9 then print “Single digit”
Step 4: Else IF N <= 99 then print “ Double digit”
Step 5: Else print “Big”
Step 6: Stop
Write an algorithm that accepts only positive integers
upto 100.
Step 1: Start
Step 2: Input N
Step 3: if (N >= 0) AND (N <= 100) then print
“ACCEPT”
Step 4: Else print “REJECT”
Step 5: Stop
Write an algorithm that performs the following :
Ask a user to enter a number. If the number is
between 5 and 15, print the word “GREEN”. If the
number is between 15 and 25 print the word
“BLUE”. If the number is between 25 and 35 print
the word “ORANGE”. If it is any other number,
print that “ALL COLOURS ARE BEAUTIFUL”.
Step 1: Start
Step 2: Input N
Step 3: If N >= 5 AND N <15 then print
“GREEN”
Step 4: Else If N >= 15 AND N <25 then print
“BLUE”
Step 5: Else If N >= 25 AND N <35 then print
“ORANGE”
Step 6: Else print “ALL COLOURS ARE BEAUTIFUL”
Step 7: Stop

You might also like