0% found this document useful (0 votes)
37 views27 pages

Algorithms and Flowcharts: Riphah International University I-14 (Islamabad)

The document discusses algorithms, flowcharts, and pseudocode, which are methods for representing the steps to solve a computational problem. It provides examples of basic flowchart symbols like rectangles, ovals, and parallelograms to represent different step types. The document also outlines characteristics of algorithms like having an input, output, and finite number of steps, and explains how to write algorithms and the advantages of using flowcharts and algorithms to design programs.

Uploaded by

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

Algorithms and Flowcharts: Riphah International University I-14 (Islamabad)

The document discusses algorithms, flowcharts, and pseudocode, which are methods for representing the steps to solve a computational problem. It provides examples of basic flowchart symbols like rectangles, ovals, and parallelograms to represent different step types. The document also outlines characteristics of algorithms like having an input, output, and finite number of steps, and explains how to write algorithms and the advantages of using flowcharts and algorithms to design programs.

Uploaded by

Tabassum Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Lecture 3

Algorithms and Flowcharts

Instructor:
Mr. Tabassum Javed

Faculty of Computing
Riphah International University I-14 (Islamabad)
Flowcharts Pseudocode &
Algorithms

2
Algorithm
• An algorithm is a sequence of steps to
solve a particular problem

• Algorithm is an ordered set of


unambiguous steps that produces a result
and terminates in a finite time

3
Characteristics of Algorithm

• Input: An algorithm may or may not require input


• Output: Each algorithm is expected to produce
at least one result
• Definiteness: Each instruction must be clear
and unambiguous.
• Finiteness: If the instructions of an algorithm
are executed, the algorithm should terminate
after finite number of steps

4
Control Structures

• Sequence: In the sequence structure, statements are


placed one after the other and the execution takes place
starting from up to down.
• Branching (Selection): In branch control, there is a
condition and according to a condition, a decision of
either TRUE or FALSE is ac
• Loop (Repetition): The Loop or Repetition allows a
statement(s) to be executed repeatedly based on certain
loop condition e.g. WHILE, FOR loops.

5
Advantages of Algorithm

• It is a step-wise representation of a solution to a given


problem, which makes it easy to understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it
is easy to understand for anyone even without
programming knowledge.
• Every step in an algorithm has its own logical sequence
so it is easy to debug.

6
How to write Algorithm
• Step 1:
– Define your algorithms input:
• Step 2:
– Define the variables:
• Step 3:
– Outline the algorithm's operations:
• Step 4:
– Output the results of your algorithm's
operations:
7
Algorithm to find sum of two
numbers

8
Flowcharts
• Diagrammatic /Graphical representation of
sequence of steps to solve a problem.

• Flowchart is often considered as a


blueprint of a design used for solving a
specific problem.

9
Advantages of Flowcharts
• Flowchart is an excellent way of communicating
the logic of a program.

• Easy and efficient to analyze problem using


flowchart.

• During program development cycle, the


flowchart plays the role of a blueprint, which
makes program development process easier.

10
Advantages of Flowcharts
• After successful development of a program, it
needs continuous timely maintenance during the
course of its operation. The flowchart makes
program or system maintenance easier.

• It is easy to convert the flowchart into any


programming language code.

11
General Rules of Flowcharts
• All boxes of the flowchart are connected with
Arrows. (Not lines)
• Flowchart symbols have an entry point on the
top of the symbol.
• The exit point for all flowchart symbols is on the
bottom except for the Decision symbol.
• The Decision symbol has two exit points; these
can be on the sides or the bottom and one side.

12
General Rules of Flowcharts
• Generally a flowchart will flow from top to
bottom. However, an upward flow can be shown
as long as it does not exceed 3 symbols.
• Connectors are used to connect breaks in the
flowchart. Examples are:
– From one page to another page.
– From the bottom of the page to the top of the same
page.

13
Flowchart Symbols

14
Basic Flowchart START
Rounded
Rectangle

Symbols Display message


“How many
hours did you
work?”

• Notice there are three Read Hours

types of symbols in Display message


“How much do
this flowchart: you get paid per
hour?”
Parallelogra
m
– rounded rectangles
Read Pay Rate
– parallelograms
– a rectangle Multiply Hours
by Pay Rate.
Rectangle
• Each symbol Store result in
Gross Pay.

represents a different Display Gross

type of operation. Rounded


Rectangle
Pay

END

15
Basic Flowchart START Terminal

Symbols Display message


“How many
hours did you
work?”

• Terminals Read Hours

– represented by Display message


“How much do
rounded rectangles you get paid per
hour?”
– indicate a starting or
ending point Read Pay Rate

Multiply Hours
by Pay Rate.
START Store result in
Gross Pay.

Display Gross
Pay

END Terminal
END

16
Basic Flowchart START

Symbols Display message


“How many
hours did you
work?”

• Input/Output Read Hours

Operations Display message


“How much do Input/Output
– represented by you get paid per
Operation
hour?”
parallelograms
– indicate an input or Read Pay Rate

output operation Multiply Hours


by Pay Rate.
Display message Store result in
Gross Pay.
“How many
Read Hours
hours did you Display Gross
Pay
work?”
END

17
Basic Flowchart START

Symbols Display message


“How many
hours did you
work?”

• Processes Read Hours

– represented by Display message


“How much do
rectangles you get paid per
hour?”
– indicates a process such
as a mathematical Read Pay Rate

computation or variable
Multiply Hours
assignment Process
by Pay Rate.
Store result in
Multiply Hours Gross Pay.
by Pay Rate.
Store result in Display Gross
Pay
Gross Pay.
END

18
Stepping Through
Stepping Through START
Output
Operation
the Flowchart
Flowchart
Display message

the
“How many
hours did you
work?”

Read Hours
How many
hours did
you work?
Display message
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: ? Display Gross


Pay Rate: ? Pay

Gross Pay: ? END

19
Stepping Through
Stepping Through START

the Flowchart
Flowchart
Display message

the
“How many
hours did you
work?”

How many Input Read Hours

hours did Operation


you work? (User types Display message
40
40) “How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40 Display Gross


Pay Rate: ? Pay

Gross Pay: ? END

20
Stepping Through
Stepping Through START

the Flowchart
Flowchart
Display message

the
“How many
hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
Output you get paid per
Operation hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Display Gross
Pay Rate: ? Pay

Gross Pay: ? END

21
Stepping Through
Stepping Through START

the Flowchart
Flowchart
Display message

the
“How many
hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour? 20
“How much do
you get paid per
hour?”

Input Read Pay Rate


Operation
(User types Multiply Hours
20) by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Display Gross
Pay Rate: 20 Pay

Gross Pay: ? END

22
Stepping Through START

Display message

the Flowchart “How many


hours did you
work?”

Read Hours
How much
do you get
paid per
Display message
hour?
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
Process: The by Pay Rate.
Store result in
Variable Contents: product of 40
times 20 is
Gross Pay.

Hours: 40 stored in
Gross Pay Display Gross
Pay Rate: 20 Pay

Gross Pay: 800 END

23
Stepping Through START

the Flowchart
Display message
“How many
hours did you
work?”

Read Hours
Your gross
pay is 800
Display message
“How much do
you get paid per
hour?”

Read Pay Rate

Multiply Hours
by Pay Rate.
Store result in
Variable Contents: Gross Pay.

Hours: 40
Output Display Gross
Pay Rate: 20 Operation Pay

Gross Pay: 800 END

24
Review

• What do each of the following symbols


represent?

(Answer on next slide) 25


Answer

• What do each of the following symbols


represent?
Decision
Terminal

Input/Output
Operation Connector

Process Module

26
27

You might also like