0% found this document useful (0 votes)
19 views51 pages

(Lecture 2) Problem Solving Process - 2025

The document outlines the problem-solving process using algorithms, flowcharts, and pseudo code, emphasizing their roles in programming. It covers the design of algorithms, the creation of flowcharts as graphical representations, and the use of pseudo code for algorithm description. Additionally, it provides examples and exercises for calculating various mathematical problems using these concepts.

Uploaded by

osobsolape12
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)
19 views51 pages

(Lecture 2) Problem Solving Process - 2025

The document outlines the problem-solving process using algorithms, flowcharts, and pseudo code, emphasizing their roles in programming. It covers the design of algorithms, the creation of flowcharts as graphical representations, and the use of pseudo code for algorithm description. Additionally, it provides examples and exercises for calculating various mathematical problems using these concepts.

Uploaded by

osobsolape12
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
You are on page 1/ 51

Problem Solving Process

using: Algorithm design,


Flowcharts and Pseudo code

Week 2  Lecture Note


The CSC121/COS121 Team @ 2025
RECOMMENDED TEXT

1. Sprankle, Maureen and Hubbard, Jim.


“Problem Solving and Programming
Concepts.” Ninth Edition. Prentice Hall.

✓ Chapter 5: “Problem Solving with


the Sequential Logic Structure”
➢ DOWNLOAD the TEXT on CSC121 page
on MOODLE
2
3
Learning Objectives
▪ Understand how to break a solution into steps called
Algorithms.
▪ Understand how to develop Flowcharts from
Algorithms.
▪ Design language-like solutions to algorithms using
Pseudo code.
▪ Apply this knowledge to a range of problems.
4
Lecture Outline
▪ General Introduction to Algorithms, Flowcharts & Pseudo
code.
▪ Algorithms – design, characteristics, examples.
▪ Flowcharts – symbols, uses & rules for drawing them.
▪ Designing language-like solutions to Algorithms using
Pseudo code.
▪ Apply this knowledge to a range of problems.
5
General Introduction to
Algorithms, Flowcharts & Pseudo code.
▪ An Algorithm shows the sequence of instructions
comprising the solution to a problem.
▪ A Flowchart is a graphical representation of an
algorithm.
▪ A Pseudo code is an informal human language-like
description of the algorithm (steps) to arrive at a
solution.
6
Introduction to Algorithms
❖An algorithm shows the sequence of instructions
comprising the solution to a specified problem.

❖It is simply the sequence of steps (of instructions)


that need to be taken to arrive at the desired solution
(goal) state, from a problem (undesired) state.
7
Designing An Algorithm
❖ To effectively design the algorithm to a problem, it is
important to identify the following:
1. The Inputs (I): data to be supplied and possibly the source of the data
e.g. keyboard input or text file,
2. The Process (P): action or computation to be performed on data,
3. The Output (O): result of computation.

▪ The IPO model is the foundation upon which the computer


model & it’s operations are built.
8
Characteristics of an Algorithm
❖An algorithm should emphasize on the ‘what’, and
not the ‘how’, leaving the details for particular
programming languages.
✓ Each step of an algorithm must be exact
✓ An algorithm must begin & terminate.
✓ An algorithm must be effective.
✓ An algorithm must be general.
9
Examples: Problem 1

1. Calculate the gross pay of an employee given


the hours worked and the rate of pay. The
gross pay is calculated by multiplying the
hours worked by the rate of pay.

10
Problem 1: Algorithm Design
1. Inputs (I): The two inputs required are
✓hours worked
✓rate of pay
▪ Note that they are both variables:
• we can represent “hours worked” as Hours while “rate of
pay” can be represented as PayRate

11
Problem 1: Algorithm Design

2. Process (P): This is the computation that will be


performed on the inputs. That is:
• multiply hours worked by the rate of pay to get gross
pay of an employee. i.e.
✓Multiply Hours by PayRate: (Hours * Payrate)

12
Problem 1: Algorithm Design
3. Output (O): Gross pay of an employee

▪ Having identified the input (I), process (P) and


output(O) in the problem1 we can thus write the
algorithm as follows:

13
The Algorithm for Problem 1
➢The STEPS of Actions (Instructions) are as
follows:
Step 1: Input Hours, PayRate
Step 2: Process (Calculate) the GrossPay:
➢Multiply Hours by PayRate
Step 3: Output (Display) the GrossPay
14
Write an Algorithm for the following: 15

• Calculate Area of a Circle


– Formula: Area of a Circle = π × radius² (Where: π
(pi) ≈ 3.1416)
• Calculate the area of a rectangle
– Formula: Area = length × width
• Calculate the total cost of items purchased
– Formula: Total Cost = price per item × quantity
• Calculate the simple interest earned on a savings
account.
– Formula: Simple Interest = (Principal × Rate × Time) / 100
Class Self Evaluation
Introduction to Flowcharts

▪ A flowchart is a graphical representation of an


algorithm.
▪ It shows a graphical (pictorial) description of the the
sequence of steps (of instructions) that need to be taken to
from a problem (undesired) state to arrive at the desired
solution (goal) state.

16
Introduction to Flowcharts

▪ A flowchart is a visual illustration of an


algorithm.
–It shows logic of an algorithm
–It emphasizes individual steps and their
interconnections; e.g. control flow from one
action to the next
17
Flowcharts Symbols

▪ In order to draw flowcharts, we use certain


symbols which are discussed in the slides that
follow:

18
19

Flowchart Symbol Explanation

• Flow lines are indicated by


straight lines with optional
arrows to show the direction of
data flow.
• The arrowhead is necessary
when the flow direction might
be in doubt.
• Flow lines are used to connect
blocks by exiting from one and
entering another.
Flowchart Symbol Explanation

• Flattened ellipses indicate the


start and the end of a module.
• A start has no flow lines
entering it and only one exiting
it;
• n end or exit has one flow line
entering it but none exiting it.

20
Flowchart Symbol Explanation

• The rectangle indicates a


processing block, for such
things as calculations, opening
and closing files, and so forth.
• A processing block has one
entrance and one exit.

21
Flowchart Symbol Explanation

• The parallelogram indicates


input to and output from the
computer memory.
• An input/output (I/O) block has
one entrance and only one exit.

22
Flowchart Symbol Explanation

• The diamond indicates a


decision.
• It has one entrance and two
and only two exits from the
NO block.
• One exit is the action when the
resultant is True and the other
Yes exit is the action when the
resultant is False.
23
Flowchart Symbol Explanation

• Rectangles with lines down


each side indicate the process
of modules.
• They have one entrance and
only one exit.

24
Flowchart Symbol Explanation

• The polygon indicates a loop with a


counter.
• The counter starts with A (the
beginning value) and is incremented
by S (the incrementor value) until the
counter is greater than B (the ending
value).
• Counter is a variable. A, B, and S may
be constants, variables, or
expressions.

25
Flowchart Symbol Explanation

• The on-page connector connects


sections on the same page
• It uses letters inside the circle to
indicate where the adjoining
connector is located. An A connects
to an A, a B to a B, etc.
• On-page connectors will have either
an entrance or an exit.

26
Flowchart Symbol Explanation

• The Off-Page connector connects


flowcharts from page to page.
• The off-page connectors use the page
number where the next part or the
previous part of the flowchart is
located.
• This allows the reader to easily follow
the flowchart.
• Off-page connectors will have either
an entrance or an exit.

27
28

On page connector
29

Off page connector


Uses of Flowcharts
1. Flowcharts facilitate communication between
programmers and business people.
2. Flowcharts play a vital role in the programming of a
problem.
3. Flowchart is helpful in understanding the logic of
complicated and lengthy problems
4. Once the flowchart is drawn, it becomes easy to write
the program in any high level language.
30
Rules for drawing Flowcharts

1. You should write the instructions inside the blocks.


2. If there is something you need to remember, you
can write a note beside a block.
– Test values of variables also can be placed beside
flowchart blocks.
– This makes the flowchart an annotated flowchart.

31
Rules for drawing Flowcharts
3. A flowchart always starts at the top of the page and
flows to the bottom.
– If you need more than one page for a flowchart, start another
column on the same page or go on to another page.
– On- and off-page connectors are used to connect parts of the
flowchart.
– A flowchart should not flow up, or sideways, or all over the page.

32
Rules for drawing Flowcharts

4. Use a computer program (e.g. Microsoft Word,


Visio, etc), or a template and a straightedge, to draw
the flowchart.
– When you use a computer program or a template, the
symbols are the same size and your flowchart will be
neater and easier to read.

33
Rules for drawing Flowcharts

5. Make the blocks big enough to write instructions so


they can be easily read.
6. Use pencil when drawing a flowchart since the first
draft may not always be perfect.

34
Recall the Algorithm Design for Problem 1

Step 1: Input Hours, PayRate


Step 2: Process (Calculate) the GrossPay:
➢Multiply Hours by PayRate
Step 3: Output (Display) the GrossPay

35
The Flowchart for Problem 1
Start

Input Hours, PayRate


1. Input Hours, PayRate
2. Process (Calculate) the GrossPay: Calculate the Grosspay

➢Multiply Hours by PayRate


3. Output (Display) the GrossPay Display GrossPay

Stop

36
Introduction to Pseudo codes
❖ Pseudo code is an artificial and informal language that
helps programmers develop algorithms.
▪ It is a "text-based" detail (algorithmic) design tool.
▪ In computer science, Pseudo code is a plain language
description of the steps in an algorithm.
▪ Pseudo code is similar to the algorithm but it is without
the steps numbering (1, 2, 3, …) and somewhat
condensed.
37
Pseudo code
▪ Pseudocode often uses structural conventions of a
normal programming language, but is intended for
human reading rather than machine reading.
▪ Although the Pseudo code closely follows the algorithm,
it is characteristically closer to what you would write in a
computer language.
▪ The rules of Pseudocode are reasonably straightforward.
38
Differences between
Algorithm and Pseudo code
▪ As we have described, an Algorithm is a set/steps of
instructions which provide solution to a specified problem.
▪ A Pseudo code, on the other hand is a method used to define
an algorithm.
▪ An algorithm can be written in natural language while pseudo
code is written in high level programming languages.
▪ Transformation of an algorithm written in pseudo code to
programming code is easier than an algorithm written in
natural language.
39
Pseudo code for Problem 1
1. Input Hours, PayRate
2. Process (Calculate) the GrossPay: ▪ Input Hours, PayRate
➢ Multiply Hours by PayRate ▪ Calculate the GrossPay:
3. Output (Display) the GrossPay
✓ GrossPay = Hours *
PayRate
You can then
write a C- ▪ Display the GrossPay
program using
this !!

40
More Problems (Examples)

▪ In the slides that follow we wish to


design the Algorithm, draw the Flowchart
and write the Pseudo code to solve the
problems

41
Problem 2
Using an Algorithm, Flowchart & Pseudo code:

1. Determine the VOLUME of a sphere.


▪ Use the formula: V = (4/3) *pi*r3 where pi is equal to
3.1416 approximately.
▪ The r is the radius of sphere.
▪ Display the Volume (V).
42
Class Evaluation

Students should brainstorm


on the solution.

43
Problem 2: Algorithm Design

▪ Input (I):
✓ Sphere Radius (r)
▪ Process (P):
– Compute the Volume (V) of the sphere
✓ Multiply 4 by constant, PI and by the cube of radius, then
✓ Divide the value obtained by 3.
▪ Output (O): Volume of the sphere
44
Algorithm for Problem 2
Begin
Step1: Read r
Step2: Compute Volume, V
✓ Multiply 4 by constant PI and by the cube of radius, then
✓ Divide the new value obtained by 3.
Step3: Display Volume of the sphere
Stop

45
Solution To
Problem 2

Pseudocode

▪ Read radius_of_sphere

▪ volume_of_sphere = (4*pi*r*r*r)/3
▪ Print volume_of_sphere

46
Problem 3
Using an Algorithm, Flowchart & Pseudo code:

❖Demonstrate how to convert the value of


temperature input in Degrees Celsius (oC)
into its equivalent Degrees Fahrenheit (oF).
▪ Use the formula: F = (9/5)*C+32.
47
Problem 3: Algorithm Design
▪ Input (I):
✓ Set all Temperature values to zero
✓ Temperature value (oC)
▪ Process (P):
– Convert temperature value (oC) to the temperature value (oF)
✓ Multiply 1.8 by temperature value (in oC), then
✓ Add the new value obtained to 32.
▪ Output (O): Temperature value (oF)

48
Algorithm for Problem 3
Begin
Step1: Set Temperature values to zero
Read Temperature value (oC)
Step2: Convert to value (oC) temperature value (oF)
✓ Multiply 1.8 by temperature value (in oC), then
✓ Add the new value obtained to 32.
Step3: Display temperature value (oF)
Stop
49
Solution To
Problem 3

Pseudocode

▪ Read temp_value (C)


▪ temp_value (F) = (1.8*C) + 32
▪ Print temp_value (F)

50
Provide the following for the given problems below:51
Algorithm Design, Algorithm, Flowchart and Pseudocode:
• Calculate Area of a Circle
– Formula: Area of a Circle = π × radius²
• (Where: π (pi) ≈ 3.1416)
• Calculate the area of a rectangle
– Formula: Area = length × width
• Calculate the total cost of items purchased
– Formula: Total Cost = price per item × quantity
• Calculate the simple interest earned on a savings account.
– Formula: Simple Interest = (Principal × Rate × Time) / 100

Assignment

You might also like