2 Chapter 2 - Algorithmic Problem Solving
2 Chapter 2 - Algorithmic Problem Solving
Algorithmic
Problem Solving
Learning Outcome:
Algorithm
Algorithmin programming
Pseudocode and flowchart
Program Development Life Cycle (PDLC)
approach for problem solving.
3
Algorithm
Algorithm is a well-defined computational
procedure that takes some value, or set of values,
as input and produces some value, or set of
values, as output.
An algorithm is thus a sequence of computational
steps that transform the input into the output.
Algorithms are always unambiguous and are used
as specifications for performing calculations, data
processing, automated reasoning and other tasks.
The algorithm can be described in two ways as
follows:
Pseudocode
Flowchart
4 October 18, 2020
Algorithm in programming
Programming is the process of taking an algorithm
and encoding it into a notation, a programming
language, so that it can be executed by a
computer.
Although many programming languages and many
different types of computers exist, the important first
step is the need to have the solution. Without an
algorithm there can be no program.
Computer science is not the study of programming.
Programming, however, is an important part of what
a computer scientist does. Programming is often the
way that we create a representation for our
solutions.
5
Pseudocode
Text-based approach words with our own
language
Organized like an outline, with differing levels of
indentation to indicate the flow of actions within the
program.
Help to ‘think out’ before actual coding
Only consists of executable instruction
6
Flow Chart
Graphical representation
Use specific shapes/symbols indicate program
behaviors and decision types
Decision Connector
Input/output Direction of flow
7
true
false
10
Pre-test Post-test
13
Step 2:
Making a plan Design the algorithm
(Algorithm Development) (pseudocode and flowchart)
Step 3:
Coding Development /
(Speaking the language Implementation
of the computer)
Step 4:
Debugging Testing
(Getting Rid of Errors)
Step 5:
Finishing the project
Maintenance
(Documentation)
15
PDLC
Step 1 : Describing the problem
A process of identifying the output, processes
and input of a program.
Defining the problem
Identify :
1. Input (given data)
2. Process
- relation between input and output
- using formula
3. Output (the result)
Example
Step 1: Problem Analysis
PDLC
Step 2: Making a plan (design the algorithm)
Planning the solution to a problem
Plan on how to solve the problem by using:
Algorithm - Set of specific, sequential steps that
describe exactly what the program must do to
complete the tasks
Algorithm can be represented by using:
1. Flow Chart
2. Pseudo Code
19
Example
Example
Flowchart Pseudocode
start
End
21
PDLC
Translate
the logic from the flowchart or
pseudocode.
There are many programming languages :
BASIC, COBOL, Pascal, Fortran, C, C++, Java
etc
Each language has it’s own syntax (rules of
language)
22
Example
Step 3: Coding / implementation / development
Step 4 - Debugging
Eliminating errors
2 types of errors:
Syntax Error – violation of rules of a
language in which computer is written
Forexample: leaving out semicolon (;) would
stop the entire program from working
Logic Error – error that occurs when a
programmer has used incorrect calculation
or left out a programming procedure.
For example : number divide by 0 (x÷0)
24
Exercise 1
Create a flowchart based on the pseudocode as
follows:
26
Exercise 2
Create a flowchart based on the pseudocode as
follows:
27
Exercise 3
Create a flowchart based on the pseudocode as
follows: