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

01 Algorithms Flowchart and Pseudocode1

Algorithm

Uploaded by

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

01 Algorithms Flowchart and Pseudocode1

Algorithm

Uploaded by

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

Chapter One

Revision on Problem Solving Techniques


ALGORITHMS,
FLOWCHART AND
PSEUDO-CODE
What is an Algorithm?
An algorithm is a set of ordered steps for solving a problem.
Algorithm can be written in natural languages like Afaan Oromo, English,
Amharic and the like.
Examples:
◦ An algorithm for preparing breakfast.
◦ An algorithm for converting Gregorian dates to
Ethiopian dates.
◦ An algorithm for calculating GCF of numbers.
◦ An algorithm for drawing a curve.
◦ An algorithm for calculating Tax, and so on....

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G. @RVU-2021 2


Algorithm in Real Life
Consider the following …
Problem: Baking a Cake
How to solve:
1.Start
2. Preheat the oven at 180oC
3. Prepare a baking pan
4. Beat butter with sugar
5. Mix them with flour, eggs and essence vanilla
6. Pour the dough into the baking pan
7. Put the pan into the oven
8. End

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
3
Examples of Algorithm
Problem: Prepare a Breakfast

1. Start
2. Prepare a Breakfast
3. End

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
4
CLASS ACTIVITY 1
Write a simple algorithm for withdrawing a sum of money
at an ATM.
Write a simple algorithm for calculating a tax.
Write a simple algorithm for comparing three different
numbers and which display the largest

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
5
Why do we need to build Algorithms?

If we wish to build a house, we need to design it first.


◦ Can you think of some possible consequences of not designing a house before
building it?

Similarly, computer programs (especially large and complex


ones) need to be designed before they are written.
◦ Can you think of some possible consequences of not designing a program before
building it?

One of the things considered when designing a computer


program is the algorithm which it will be based on.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
6
Algorithms in Program Design
A computer program is built to solve a certain
problem.
Examples:
1. A program to calculate the grade obtained given
a mark.
2. A program to convert a Gregorian date to
Ethiopian date.
3. A program to produce a document.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
7
Below are steps (in fact, an algorithm) for
building a program to solve a particular problem:

◦ Analyze the problem


◦ Design a computer solution to the problem
by developing an algorithm.
◦ Write a computer program based on the
algorithm.
◦ Test the program.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
8
How to Specify an Algorithm?
An algorithm must be specific enough so that it
can be conveniently translated into a computer
program (using C++, for example).
An algorithm can be specified:
◦ Textually
For example, using pseudo code (see later)
◦ Graphically
For example, using flowcharts or UML activity
charts

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
9
FLOWCHARTS
A flowchart is a graphical representation of the sequence of operations
in a program.
An algorithm can be represented graphically using a flowchart.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
10
FLOWCHART NOTATIONS
Symbol Semantic
Start/End

Process

Input/Output

Test

Connector

Flow of activities
FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.
@RVU-2021
11
FLOWCHART: EXAMPLE 1
Start Algorithm starts here

Input
Gregorian date Input data from user

Convert Gregorian
date to Ethiopian date Perform the date conversion

Display
Display the result
Ethiopian date

End Algorithm ends here

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
12
FLOWCHART: EXAMPLE 2
Start
• length, width and area
Input are referred to as
length, width variables.
• A variable is like a box
area ← length X width in which a value can be
stored
Output
area

End
FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.
@RVU-2021
13
FLOWCHART: EXAMPLE 3
Selection
Start

Input
height

false true
height > 1.6?

Output Output
“You are short!” “You are tall!”

End

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
14
FLOWCHART: EXAMPLE 4
Repetition (looping)

Start

Output
“Thank you!”

Input
stop

false
stop = 1?

true
End
FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.
@RVU-2021
15
CLASS ACTIVITY 2
Draw a flowchart which represents the algorithm built in CLASS
ACTIVITY[1].

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
16
PSEUDOCODE
An outline of a program, written in a form that can easily be converted into real
programming statements.
It resembles the actual program that will be implemented later.
However, it cannot be compiled nor executed.
Pseudocode normally codes the following actions:

◦ Initialization of variables, Assignment of values to the variables


◦ Arithmetic operations, Relational operations

A coding technique where precise descriptions of procedures are


written in easy-to-read language constructs without the attention to the
syntax rules of a computer language.
FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.
@RVU-2021
17
Example of Pseudocode
1. Start
2. Read quantity
3. Read price_per_kg
4. price  quantity * price_per_kg
5. Print price
6. End
The above pseudocode is designed/developed to
calculate the price of some quantity.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
18
You should now know…
what an algorithm is.
when an algorithm should be developed when building
a computer program.
the basic steps in building a computer program to solve
a problem.
what flowcharts are.
how to represent algorithms graphically using
flowcharts.

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
19
Individual Assignment1 (10%)

What is a Divide and Conquer strategies in algorithm?


Give a simple example
Important Tips
Date of submission November 15, 2021
Mode of Submission: in Hard-Copy
Note more than 2 pages

FUNDAMENTALS OF PROGRAMMING IN C++ COMPILED BY YADETA G.


@RVU-2021
20

You might also like