Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

2-Problem solving techniques

The document outlines problem-solving techniques, emphasizing the importance of algorithms and pseudocode in programming. It details the phases of program development, steps in problem-solving, and provides examples of algorithms and flowcharts. Additionally, it discusses the advantages and limitations of flowcharts in programming tasks.

Uploaded by

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

2-Problem solving techniques

The document outlines problem-solving techniques, emphasizing the importance of algorithms and pseudocode in programming. It details the phases of program development, steps in problem-solving, and provides examples of algorithms and flowcharts. Additionally, it discusses the advantages and limitations of flowcharts in programming tasks.

Uploaded by

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

PROBLEM

SOLVING
TECHNIQUES
INSTRUCTOR: JAVERIA NAZ
What is Problem
Solving?
 A process of identifying a problem and finding its best
solution is known as problem solving.
 In this process the descriptions of problem are
transformed into its solution.
 The problem can be solved in different ways.
 However, the most suitable way should be selected to
solve a problem.
Phases of Program
Development
The general phases of program development are:
1. Planning
2. Analysis
3. Design
4. Coding
5. Testing
6. Implementation
7. Maintenance
Problem Solving
Techniques
A typical programming task can be divided into two
phases:
1. Problem solving phase
 produce an ordered sequence of steps that
describe solution of problem
 this sequence of steps is called an algorithm
2. Implementation phase
 implement the program in some programming
language
Steps in Problem Solving

 First produce a general algorithm (one can use


pseudocode)
 Refine the algorithm successively to get step by step
detailed Algorithm that is very close to a computer
language.
 Pseudocode is an artificial and informal language
that helps programmers develop algorithms.
Pseudocode is very similar to everyday English.
Algorithm
 A computer algorithm is a detailed step by step
method for solving the problem
 An algorithm is a sequence of Clear-cut instructions
for solving the problem in a finite amount of time.
 More Generally an algorithm is any well defined
computational procedure that takes collection of
elements as input and produces collection of
elements as output.
Points to Note:
A precise sequence of a limited number of unambiguous,
executable steps that terminates in the form of a solution.
3 Requirements:
1. Sequence is:
◦ Precise
◦ Consists of a limited number of steps
2. Each step is:
◦ Unambiguous
◦ Executable
3. The sequence of steps terminates in the form of a
solution
7
Pseudocode
 Pseudocode (pronounced SOO-doh-kohd) is a detailed
yet readable description of what a computer program or
algorithm must do.
 Expressed in a formally-styled natural language rather
than in a programming language.
 Pseudocode is sometimes used as a detailed step in the
process of developing a program.
 It allows designers or lead programmers to express the
design in great detail and provides programmers a
detailed template for the next step of writing code in a
specific programming language.
Pseudocode & Algorithm

Example 1
Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.
Pseudocode & Algorithm
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
Pseudocode & Algorithm
Detailed Algorithm
Step 1: Start
Step 2: Input M1,M2,M3,M4
Step 3: GRADE = (M1+M2+M3+M4)/4
Step 4: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
end if
Step 5: Stop
The Flowchart
(Dictionary) A schematic representation of a sequence of
operations, as in a manufacturing process or computer
program.
(Technical) A graphical representation of the sequence of
operations in an information system or program.
Information system flowcharts show how data flows from
source documents through the computer to final
distribution to users. Program flowcharts show the
sequence of instructions in a single program or subroutine.
Different symbols are used to draw each type of flowchart.
The Flowchart

A Flowchart
◦ shows logic of an algorithm
◦ emphasizes individual steps and their interconnections
◦ e.g. control flow from one action to the next
Flowchart Symbols
Name Symbol Use in Flowchart

Oval Denotes the beginning or end of the program

Parallelogram Denotes an input operation

Rectangle Denotes a process to be carried out


e.g. addition, subtraction, division etc.

Diamond Denotes a decision (or branch) to be made.


The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)

Hybrid Denotes an output operation

Flow line Denotes the direction of logic flow in the program


Example
START

Step 1: Start
Input
M1,M2,M3,M4 Step 2: Input M1,M2,M3,M4
Step 3: GRADE =(M1+M2+M3+M4)/4
GRADE(M1+M2+M3+M4)/4
Step 4: if (GRADE <50) then
Write “FAIL”
N IS Y
GRADE<5 else
0
Write “PASS”
WRITE WRITE
PASS FAIL end if
Step 5: Stop
STOP
Example 2
Write an algorithm and draw a flowchart to convert the
length in feet to centimeter.
Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying Lft with 30
Print length in cm (Lcm)
Example 2
Flowchart
Algorithm
START

Step 1: Start
Input
Step 2: Input Lft Lft

Step 3: Lcm = Lft x 30


Lcm = Lft x 30
Step 4: WRITE Lcm
Step 5: Stop WRITE
LCM

STOP
Example 3
Write an algorithm and draw a flowchart that will read the
two sides of a rectangle and calculate its area.
Pseudocode
Input the width (W) and Length (L) of a rectangle
Calculate the area (A) by multiplying L with W
Print A
Example 3

Algorithm
START
Step 1: Start
Input
Step 2: Input W,L W, L

Step 3: AL x W
Step 4: WRITE A A LxW
Step 5: Stop
WRITE
A

STOP
Example 4
Write an algorithm that reads two values, determines the largest value
and prints the largest value with an identifying message.
ALGORITHM
Step 1: Start
Step 2: Input VALUE1, VALUE2
Step 3: if (VALUE1 > VALUE2) then
MAX  VALUE1
else
MAX  VALUE2
endif
Step 4: Write “The largest value is”, MAX
Step 5: Stop
Example 4 START

Input
VALUE1,VALUE2

Y is N
VALUE1>VALUE2

MAX  VALUE1 MAX  VALUE2

WRITE
MAX

STOP
Advantages of
Flowchart
1. With the help of flowchart logic of program can
be described easily and more effectively.
2. Flowchart are a part of design phase, by using
flowchart maintenance of operational program
become more easy.
3. A flowchart help programmer in writing a
program.
4. A flowchart also help in debugging the program
Limitations of
Flowchart
Flowcharts also have some limitations. These
limitations are as follows:
1. It is difficult to draw a flowchart for complex
problem.
2. The flowchart has to be redrawn or redesigned if
any change in the problem /requirements is
required.
Questions:
1. Write pseudocode, algorithm and also draw flowchart for
the following:

 Find whether the given number is even or odd?


 Find Largest number among three numbers.
 Find Area and Circumference of a circle. Where:
 Area
 Circumference
Quiz-2 13-11-2020
1. Explain Pseudocode. (5)
2. Write an algorithm also draw flowchart to calculate : (5 + 5)
 Area of Triangle:

You might also like