COMPUTER PROGRAMMING 2
Algorithm and Pseudocode
PRESENTED BY:
Jhaun Paul G. Enriquez
SHS ICT Faculty
1
Uses steps to
accomplish a task
ALGORITHMS
COMPUTER PRORAMMING 2 2
LEARNING OUTCOMES:
1. Identify concepts and underlying principles in designing
program logic
2. Describe the types of algorithms that can be used in creating
programs
3. Differentiate the two forms of algorithm
4. Design program logic based on specified requirements
COMPUTER PRORAMMING 2 3
Introduction to Algorithms
• Set of steps to accomplish a task or how
to arrive at a solution to a problem
• Created by Muhammad al-Khwarizmi
(Persian Mathematician)
• Often used for calculation, data
processing and programming
• Algorithms can be expressed in any
language
COMPUTER PRORAMMING 2 4
Introduction to Algorithms
• Algorithms for making things will often be divided into
sections
INPUT PROCESS OUTPUT
Components needed to Actions/steps/methods Required outcome to
accomplish the task to be undertaken be produced
COMPUTER PRORAMMING 2 5
MAKING A PANCAKE
COMPUTER PRORAMMING 2 6
Introduction to Algorithm
RUBIK’S CUBE ALGORITHM 3 X 3
COMPUTER PRORAMMING 2 7
TYPES OF ALGORITHMS
• Branch and Bound Algorithm
• Compression Algorithm
• Route Finding Algorithm
• Rendering Algorithm
• Optimization and Scheduling
Algorithm
COMPUTER PRORAMMING 2 8
FORMS OF ALGORITHM
PSEUDOCODE FLOWCHART
• a kind of structured English for • diagram that shows the logic of
describing algorithms the program
• expressed in program language • use simple geometric shapes to
like constructs depict processes and arrows to
show process/data flow and
relationships
COMPUTER PRORAMMING 2 9
What is a Pseudocode?
• A type of structured English that is used to specify an
algorithm.
• Fake code that specifies the steps required to accomplish
the task
• Cannot be compiled nor executed, and there are no real
formatting or syntax rules.
COMPUTER PRORAMMING 2 10
Purpose of Pseudocodes
To describe how an To design code in a
algorithm works group setting
(Reduced Complexity) (Increase flexibility)
To explain a computing
process to less-technical users
(Ease of Understanding)
“Writing Pseudocode will save you time later during the
construction & testing phase of a program's development.”
COMPUTER PRORAMMING 2 11
How to Write Pseudocode Statements?
1. A computer can receive information
• Read (information from a file)
• Get (information from the keyboard)
2. A computer can put out information
• Write (information to a file)
• Display (information to the screen)
COMPUTER PRORAMMING 2 12
How to Write Pseudocode Statements?
4. A computer can assign a value to a piece of data
CASE 1 CASE 2
Give data an initial value Assign a value as a result of a process
Initialize or Set sum = 5 + 4;
CASE 3
Keep a piece of information for later use
Save or Store
COMPUTER PRORAMMING 2 13
How to Write Pseudocode Statements?
5. A computer can compare two piece of information and
select one of two alternative actions (conditionals)
IF condition THEN EXAMPLES:
some action
ELSE
alternative action
END IF
COMPUTER PRORAMMING 2 14
How to Write Pseudocode Statements?
6. A computer can repeat a group of actions (loop)
WHILE condition (is true) EXAMPLES:
some action
ENDWHILE
FOR a number of times
some action
ENDFOR
COMPUTER PRORAMMING 2 15
PSEUDOCODE: Do’s and Don’ts
DO:
• Proper naming conventions
• Simple and concise
• Use indentations and white spaces
DONT:
• Make abstract statements
• Make too generalized statements
COMPUTER PRORAMMING 2 16
ALGORITHM TO A PSEUDOCODE
PROBLEM 1: Create a program that will calculate the pay of an
employee.
Algorithm
1. Determine working hours
2. Determine employee rate
3. Calculate the pay by multiplying
working hours and employee’s rate
4. Display employee’s pay
COMPUTER PRORAMMING 2 17
ALGORITHM TO A PSEUDOCODE
PROBLEM 2: Write a program that accepts two numbers from the
user and prints out the difference of those number.
Algorithm Pseudocode
1. User encodes the first number. BEGIN
2. User encodes the second number. Let num1 and num2 = 0
3. Find the difference between the Prompt user to input num1
first and second numbers. Prompt user to input num2
difference = num1 – num2
4. Show the difference.
Output difference
END
COMPUTER PRORAMMING 2 18
COMPUTER PRORAMMING 2 19
Resources:
• Padre, Nilo M. et al. (2016). Programming Concepts Logic Formulation, 1st ed.
Manila: Unlimited Books Library Services & Publishing, Inc.
• Why Algorithms are called Algorithms. BBC Ideas (2019). Retrieved from:
https://www.youtube.com/watch?v=oRkNaF0QvnI&feature=emb_logo
• What is an algorithm and why should you care? Khan Academy (2015).
Retrieved from: https://www.youtube.com/watch?v=CvSOaYi89B4&t=180s
• What is Pseudocode And How Do You Use It? CodeCademy (2019). Retrieved
from: https://www.youtube.com/watch?v=PwGA4Lm8zuE
COMPUTER PRORAMMING 2 20
COMPUTER PRORAMMING 2