You are on page 1of 17

Information Technology

Grade 11
Algorithms

L/O/G/O Teacher: Samlall Rabindranauth


Types of Algorithms

There are three (3) types of


algorithms:
❖Narrative
❖Pseudocode
❖Flowchart
Narrative Algorithm

A narrative algorithm is an algorithm


expressed in english sentences that explains
all the steps in the algorithm.
This algorithm uses terms like “get” to acquire
input, “display” to output a variable or
statement, “calculate” to indicate a calculation
step, “assign” to set a value to a variable, and
“store” to place the values of input or
calculation in a variable.
Eg of a Narrative Algorithm

➢ Start
➢ Get three numbers
➢ Store the numbers as a,b,c
➢ Calculate the total of the three numbers by
adding them together
➢ Store the results as SUM
➢ Calculate the average by dividing the SUM
by 3
➢ Store the results as AVG
➢ Display SUM and AVG
➢ Stop
Pseudocode Algorithm

Pseudocode or False code 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.
Terms used in pseudocode algorithms

• For input: input, read


• For output: output, write, display
• For calculations: set
• For assignments: set
• For bounded iteration: For … do
• For unbounded iteration: While…do
• For Selection: If…then or If…then...else…
Example of pseudocode
algorithms

Start
Write “ Please enter 3 numbers”
Read a,b,c
Set sum a+b+c
Set average sum/3
Write “The sum is: “, sum
Write “The average is :” average
Stop
Example of pseudocode using
selection
Start
Write “Please enter 2 number”
Read a, b
If a>b then
Write “The first number is higher”
Else
Write “The second number is higher”
Endif
Stop
Pseudocode using Bounded
iteration
Start
Set i 1
For i = 1 to 10 do
Set multiple[i] i*2
Write “1 x 2 = ”, multiple[i]
i=i+1
Endfor
Stop
Flowchart

A flowchart is a diagram that


depicts a process, system or
computer algorithm. They are
widely used in multiple fields to
document, study, plan, improve
and communicate often complex
processes in clear, easy-to-
understand diagrams.
Shapes used in a flowchart
Purpose Shape Name Shape

Start/Stop Oval

Input/Output Parallelogram

Assignment/Calculation Rectangle

Decision Rhombus

Continuation Circle

Direction Arrow
Examples of a flowchart
Truth Tables

Truth tables summarize how we


combine two logical conditions based
on AND, OR, and NOT. Logic tells us
that if two things must be true in
order to proceed them both
condition_1 AND condition_2 must be
true. If it only takes one out of two
things to be true, then condition_1 OR
condition_2 must be true.
Example of a Truth table
Lets say a student passes a subject if he/she has an A, B or C in a subject
otherwise he/she fails. The truth table below uses 1 as being yes and 0 as
being no.

Name A B C D F Pass/Fail

John 1 0 0 0 0 1

Patty 0 0 1 0 0 1

Mia 0 0 0 0 1 0

Zack 0 0 0 1 0 0

Kate 0 0 0 0 1 0

Tom 0 0 0 1 0 0

Cindy 0 1 0 0 0 1
Trace Table
A trace table is a technique used to test algorithms in order to
make sure that no logical errors occur while the calculations
are being processed. The table usually takes the form of a
multi-column, multi-row table; With each column showing a
variable, and each row showing each number input into the
algorithm and the subsequent values of the variables.

Trace tables are typically used in schools and colleges when


teaching students how to program. They can be an essential
tool in teaching students how certain calculations works and
the systematic process that is occurring when the algorithm
is executed. They can also be useful for debugging
applications, helping the programmer to easily detect what
error is occurring, and why it may be occurring.
Example of a Trace Table

https://www.101computing.net/wp/wp-content/uploads/trace-table-s.gif
The End

L/O/G/O

You might also like