Chapter 3: Basic Concepts of Algorithm
Chapter 3: Basic Concepts of Algorithm
ALGORITHM
1
LESSON OUTCOMES
Upon completion of this chapter, students should be able to:
2
PROBLEM SOLVING PROCESS
Algorithm is a step by step sequence of precise instructions that
must terminates and describes how the data is processes to
produce the desired output. During problem analysis, you should
specify requirement as below:1.
1. Input
2. Processing
3. Output
3
PROBLEM-SOLVING PROCESS
EXAMPLE # 1: Display your name
Input Process
Name = KidName Output
KidName
FatherName + Name
FatherName
Algorithm
1. Input KidName, FatherName
2. Name= KidName + FatherName
3. Output Name
4
PROBLEM-SOLVING PROCESS
EXAMPLE # 2: Compute the sum of 3 numbers
Algorithm:
1. Input Number1, Number2, Number3
2. Calculate Sum by
Sum = Number 1 + Number 2 + Number 3
3. Display Sum
5
PROBLEM-SOLVING PROCESS
EXAMPLE # 3: Calculate and display the average mark of three students
Problem solving process:
7
PROBLEM-SOLVING PROCESS
EXAMPLE # 4 (Answer)
8
PROBLEM-SOLVING PROCESS
EXAMPLE # 4 (Answer)
Algorithm:
9
ALGORITHM REPRESENTATION
Design tools are used to document a solution algorithm. Two
structured design tools are Flowcharts and Pseudocode.
FLOWCHARTS
PSEUDOCODE
ALGORITHM REPRESENTATION
Flowchart
11
ALGORITHM REPRESENTATION
Flowchart - Symbols
12
ALGORITHM REPRESENTATION
Flowchart - Symbols
13
ALGORITHM REPRESENTATION
Flowchart - Symbols
14
ALGORITHM REPRESENTATION
Flowchart - Symbols
15
ALGORITHM REPRESENTATION
Flowchart - Examples
16
ALGORITHM REPRESENTATION
Flowchart - Examples
17
ALGORITHM REPRESENTATION
1.Flowchart - Examples
18
ALGORITHM REPRESENTATION
Flowchart – Sequential Structures
S EQ U E N T I A L ST R U C T U R E
19
ALGORITHM REPRESENTATION
Flowchart – Selection Structures
S E L EC T I O N ST R U C T U R E
20
ALGORITHM REPRESENTATION
Flowchart – Repetition Structures
R E P E T I T I O N / LO O P
ST R U C T U R E
21
ALGORITHM REPRESENTATION
Pseudocode
Begin
Input KidName, FatherName
Name = KidName + FatherName
Display Name
End
23
ALGORITHM REPRESENTATION
Pseudocode
Example # 2 – Compute the sum of three numbers
Input Process Output
Number 1 Sum = Number 1
Number 2 + Number 2 + Sum
Number 3 Number 3
Begin
Input Number1, Number2, Number3
Sum = Number1 + Number2 + Number3
Display Sum
End
24
ALGORITHM REPRESENTATION
Pseudocode
Example # 3 – Calculate & display the average of 3 students
Input Process Output
Mark A Average = (Mark A
Mark B + Mark B + Average
Mark C Mark C)/3
Begin
Input Mark A, Mark B, Mark C
Sum = Mark A + Mark B + Mark C
Average = Sum / 3
Display Average
End
25
END OF CHAPTER 3
26