0% found this document useful (0 votes)
48 views26 pages

Chapter 3: Basic Concepts of Algorithm

This chapter discusses basic concepts of algorithms including the problem solving process, algorithm representation using flowcharts and pseudocode, and examples. The problem solving process involves specifying the input, processing, and output. Flowcharts use geometric shapes and lines to show the logic and steps of an algorithm. Pseudocode describes the processing in a structured English-like form. Examples demonstrate summing numbers, calculating averages, and other processes.

Uploaded by

khi2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views26 pages

Chapter 3: Basic Concepts of Algorithm

This chapter discusses basic concepts of algorithms including the problem solving process, algorithm representation using flowcharts and pseudocode, and examples. The problem solving process involves specifying the input, processing, and output. Flowcharts use geometric shapes and lines to show the logic and steps of an algorithm. Pseudocode describes the processing in a structured English-like form. Examples demonstrate summing numbers, calculating averages, and other processes.

Uploaded by

khi2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

CHAPTER 3: BASIC CONCEPTS OF

ALGORITHM

CSC118 FUNDAMENTALS OF ALGORITHM DEVELOPMENT

1
LESSON OUTCOMES
Upon completion of this chapter, students should be able to:

 Apply Problem Solving process


 Define what is Algorithm Representation
 
 

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

Input Process Output


Data (Algorithm) Information

3
PROBLEM-SOLVING PROCESS
EXAMPLE # 1: Display your name

 Problem solving process

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

 Problem solving process:


Input Process Output
Number 1 Sum = Number 1 + Sum
Number 2 Number 2 +
Number 3 Number 3

 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:

Input Process Output


Mark A Average = (Mark A + Average
Mark B Mark B + Mark C)/3
Mark C
 Algorithm:
1. Input Mark A, Mark B, Mark C
2. Calculate Average by
i. Adding the numbers and
Sum = Mark A + Mark B + Mark C
ii. Dividing the sum by 3
Average = Sum / 3
3. Display Average
6
PROBLEM SOLVING PROCESS
EXAMPLE # 4

 Calculate and display the salary of 100 employees. The input is


basic salary, claim and overtime The gross salary (income) is
the summation of these three items . The salary is the income
deducts the EPF which the EPF is the 8% of the basic salary.

7
PROBLEM-SOLVING PROCESS
EXAMPLE # 4 (Answer)

 Problem solving process:

1. Input : Basic salary, claim, overtime


2. Process : Income = Basic salary + claim + overtime
EPF = Basic salary * 0.08
Salary = Income – EPF
3. Output : Salary

8
PROBLEM-SOLVING PROCESS
EXAMPLE # 4 (Answer)
 Algorithm:

1. Input Basic salary, claim, overtime


2. Calculate Income
Income = Basic salary + claim + overtime
Calculate EPF
EPF = Basic salary * 0.08
Calculate Salary
Salary = Income – EPF
3. Display Salary
4. Repeat step 1-3 for 100 times

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

 Flowchart graphically shows the logic in solution algorithm that


produce in early 1960s
 Its show the step by step solution using symbols which represent a
task
 The symbols used consist of geometrical shapes that are connected
by flow lines.

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

Example # 1 - Display your name


KidName
Fathername

Input Process Output


Name=KidName KidName Name=KidName Name
+ FatherName
Fathername + FatherName

16
ALGORITHM REPRESENTATION
Flowchart - Examples

Example # 2– Compute the sum of 3


numbers

Input Process Output


Number 1 Sum = Number 1
Number 2 + Number 2 + Sum
Number 3 Number 3

17
ALGORITHM REPRESENTATION
1.Flowchart - Examples

Example # 3 – Calculate and display the


average mark of 3 students

Input Process Output


Mark A Average =
Mark B (Mark A + Mark B Average
Mark C + Mark C)/3

18
ALGORITHM REPRESENTATION
Flowchart – Sequential Structures

S EQ U E N T I A L ST R U C T U R E

 The sequential structure has one entry


point and one exit point.
 No choices are made and no
repetition.
 Statements are executed in sequence,
one after another without leaving out
any single statement.

19
ALGORITHM REPRESENTATION
Flowchart – Selection Structures

S E L EC T I O N ST R U C T U R E

 The selection structure is used to allow


choices to be made.
 The program executes particular
statements depending on some
condition(s).
 C++ uses the if-else and switch
statement for making decision.

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

 Statements are executed repeatedly


while certain condition remains true.
 In C++, while, do-while and for are the
statements commonly used within the
repetition structure.

21
ALGORITHM REPRESENTATION
Pseudocode

 Pseudocode is a tool programmers use to help them plan an


algorithm
 It used English like phrases to describe the processing
 It is not standardized since every programmer has his own way of
planning the algorithm
 Criteria of a good pseudocode are:
a. Easy to understand, precise and clear.
b. Gives the correct solution in all cases.
c. Eventually ends.
CSC118 FUNDAMENTALS OF ALGORITHM DEVELOPMENT 22
ALGORITHM REPRESENTATION
Pseudocode
Example # 1 - Display your name
Input Process Output
KidName Name=KidName Name
Fathername + FatherName

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

You might also like