0% found this document useful (0 votes)
21 views

Problem Solving Techniques

Computational problem solving involves expressing solutions to problems in a way that can be carried out by a computer. It discusses problem solving techniques like algorithms, flowcharts, pseudocode, and programs. An algorithm is a sequence of instructions to solve a problem, while a flowchart uses basic shapes and arrows to represent the flow of a program. Pseudocode resembles a program but uses plain English instead of code syntax. Examples are provided for each technique.

Uploaded by

bhanumv123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Problem Solving Techniques

Computational problem solving involves expressing solutions to problems in a way that can be carried out by a computer. It discusses problem solving techniques like algorithms, flowcharts, pseudocode, and programs. An algorithm is a sequence of instructions to solve a problem, while a flowchart uses basic shapes and arrows to represent the flow of a program. Pseudocode resembles a program but uses plain English instead of code syntax. Examples are provided for each technique.

Uploaded by

bhanumv123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

computational problem solving:

Computational thinking is the process of approaching


a problem in a systematic manner and creating and
expressing a solution such that it can be carried out
by a computer.
PROBLEM SOLVING:
Problem solving is the systematic approach to define the problem and
creating number of solutions.

The problem solving process starts with the problem specifications and
ends with a Correct program.
PROBLEM SOLVING TECHNIQUES
• Problem solving technique is a set of techniques that helps in providing logic for
solving a problem.
• Problem Solving Techniques:

Problem solving can be expressed in the form of

1. Algorithms.

2. Flowcharts.

3. Pseudo codes.

4. programs
ALGORITHM
It is defined as a sequence of instructions that describe a method for
solving a problem. In other words it is a step by step procedure for
solving a problem.
Properties of Algorithms
• Should be written in simple English

• Each and every instruction should be precise and


unambiguous.

• Instructions in an algorithm should not be repeated


infinitely.

• Algorithm should conclude after a finite number of steps.

• Should have an end point

• Derived results should be obtained only after the


algorithm terminates.
Qualities of a good algorithm
The following are the primary factors that are often used to judge the quality
of the algorithms.

Time – To execute a program, the computer system takes some amount of


time. The lesser is the time required, the better is the algorithm.

Memory – To execute a program, computer system takes some amount of


memory space. The lesser is the memory required, the better is the algorithm.

Accuracy – Multiple algorithms may provide suitable or correct solutions to a


given problem, some of these may provide more accurate results than others,
and such algorithms may be suitable.
Example

Write an algorithm to print „Good Morning”

Step 1: Start

Step 2: Print “Good Morning”

Step 3: Stop
BUILDING BLOCKS OF ALGORITHMS :

Statements: input data-information given to the program & output information.


State: Transition from one process to another process under specified condition with in a
time is called state.
Control flow:
The process of executing the individual statements in a given order is called control
flow.

The control can be executed in three ways

1. sequence

2. selection

3. iteration
Sequence:
All the instructions are executed one after another is called sequence execution.

Example:

Add two numbers:


Step 1: Start

Step 2: get a,b

Step 3: calculate c=a+b

Step 4: Display c

Step 5: Stop
Selection:
A selection statement causes the program control to be transferred to a
specific part of the program based upon the condition.
If the conditional test is true, one part of the program will be executed,
otherwise it will execute the other part of the program.
Example
Write an algorithm to check whether he is eligible to vote?

Step 1: Start

Step 2: Get age

Step 3: if age >= 18 print “Eligible to vote”

Step 4: else print “Not eligible to vote”

Step 6: Stop
Iteration:
In some programs, certain set of statements are executed again and
again based upon conditional test. i.e. executed more than one time.
This type of execution is called looping or iteration.
Example
Write an algorithm to print all natural numbers up to n

Step 1: Start

Step 2: get n value.

Step 3: initialize i=1

Step 4: if (i<=n) go to step 5 else go to step 7

Step 5: Print i value and increment i value by 1

Step 6: go to step 4

Step 7: Stop
Pseudocode:
Python pseudocode is more like an algorithmic representation of the
code involved.
This means when a code is expected to be formulated it cannot be
directly drafted.
The code will need to be first generated into a Python pseudocode and
then it needs to be formulated into an actual code.
Basic rules before writing pseudocode:
• Write only one statement per line.
• Write what you mean, not how to program it
• Give proper indentation to show hierarchy and make code
understandable.
• Make the program as simple as possible.
WRITE A PSEUDOCODE TO FIND THE LARGEST OF TWO NUMBERS.
BEGIN

NUMERIC nNum1,nNum2
DISPLAY "ENTER THE FIRST NUMBER : "
INPUT nNum1

DISPLAY "ENTER THE SECOND NUMBER : "


INPUT nNum2

IF nNum1 > nNum2


DISPLAY nNum1 + " is larger than "+ nNum2
ELSE
DISPLAY nNum2 + " is larger than " + nNum1

END
WRITE A PSEUDOCODE TO FIND THE SUM OF TWO NUMBERS.
begin
numeric nNum1,nNum2,nSum
display "ENTER THE FIRST NUMBER : "
accept nNum1
display "ENTER THE SECOND NUMBER : "
accept nNum2
compute nSum=nNum1+nNum2
display "SUM OF THESE NUMBER : " nSum
end
WRITE A PSEUDOCODE TO FIND THE AREA OF
RECTANGLE.
begin
numeric nLen,nBrd,nAre
display "ENTER THE LENGTH OF RECTANGLE : "
accept nLen
display "ENTER THE BREADTH OF RECTANGLE : "
accept nBrd
nAre=nLen*nBrd
display "AREA OF RECTANGLE : " nAre
end
Flowcharts:
• Flowcharts graphically represent the flow of a program. There are four
basic shapes used in a flow chart. Each shape has a specific use:
• oval: start / end
• parallelogram: input / output
• rectangle: calculations
• diamond: selection structures
Arrows connect the basic shapes in a flowchart. The shapes and arrows of a
flowchart describe the flow of a program from start to end. Flowcharts typically
flow from the top to the bottom or flow from the left to the right.
A flowchart that describes this simple program is shown.

The Python code that corresponds to


this flowchart is:
# start print("Output!") # end
Add ‘two’ to the user input :

The Python code that corresponds to this flow chart is:

# start
num = input("Enter a number: ")
num = float(num)
num_plus_2 = num + 2
print(num_plus_2)
# end
To check number is greater than zero :

The Python code that corresponds to this flow chart is:

# start
num = input("Enter a number: ")
num = float(num)
if num>0:
print("Greater than 0")
# end
Program :
If the number is greater than zero, then the program prints "Greater
than 0". If the number is less than zero, then the program prints "Less
than 0". Then the program prints "Done" and the program ends.
The Python code that corresponds to this flow chart is:

# start
num = input('Enter a number: ')
num = float(num)
if num>0:
print('num greater than zero')
if num<0:
print('num less than zero')
print('Done')
# end

You might also like