Chap 02 - Intro To Problem-Solving and Algorithm Design
Chap 02 - Intro To Problem-Solving and Algorithm Design
Introduction to
Problem-Solving and
Algorithm Design
CSC121 – Introduction to Algorithm Design and Development
DEFINITION :
● A state of difficulty that needs to be resolved or.
● A question raised for consideration or solution.
● A difficulty: a matter about something difficult to decide on what to do.
● A question to be answered or solve.
Types of Problems :
KNOWLEDGE-LEAN KNOWLEDGE-RICH
PROBLEMS PROBLEMS
Examples of Problems :
DEFINITION :
● Solution: an action to solve a problem.
● Solving a problem: making the problem go away, so that it does not
exist any longer.
● Algorithms
○ A step by step procedures that accepts data, manipulate them
based on the prescribed steps, to achieve the desired value(s)
or tasks.
03
Program Development Life Cycle
3.0 Program Development Life Cycle
05
Program
Maintenance &
Documentation 01
Problem
Analysis
04
Program
Testing &
Debugging
02
Algorithm
Design
03
Algorithm
Implementation
3.1 Program Development Life Cycle :
Problem Analysis
Steps of
Algorithm
Implementation
3.4 Program Development Life Cycle :
Program Testing and Debugging
If you execute the program, provide the value 2 as input to the program,
and the answer 4 is displayed, you have executed one successful test
run of the program. However, if the answer 40 is displayed, maybe the
program contains a logical error.
3.5 Program Development Life Cycle :
Program Maintenance and Documentation
Input
Devices
4.2 Details of Problem Analysis : Process
Output
Devices
4.4 Details of Problem Analysis
Example
Calculate and
display the ● Mark A Average =
(Mark A +
average mark of ● Mark B Average
Mark B +
three students ● Mark C Mark C) /3
05
Basic Concepts of Algorithm
and Algorithm Presentation
5.0 Basic Concepts of Algorithm
● Number 1 Sum =
Number 1 +
● Number 2 Sum
Number 2 +
Compute the ● Number 3 Number 3
sum of 3
numbers Input Number1, Number2, Number3
Calculate Sum by
ALGORITHM
Sum = Number 1 + Number 2 + Number 3
Display Sum
5.0 Basic Concepts of Algorithm
Example
EXAMPLE 2 INPUT PROCESS OUTPUT
● Mark A Average =
(Mark A +
● Mark B
Mark B + Average
Calculate and ● Mark C Mark C) /3
display the
Input Mark A, Mark B, Mark C
average mark Calculate Average by
of three Adding the numbers and
ALGORITHM Sum = Mark A + Mark B + Mark C
students
Dividing the sum by 3
Average = Sum / 3
Display Average
5.1 Algorithm Presentation
PSEUDOCODE FLOWCHART
Start
Read number1
Compute Read number2
Example the sum of Sum = number1 + number2
2 numbers Display “ The sum is ”
Display Sum
End
5.3 Algorithm Presentation : Flowchart
Selection process or
Selection / Decision condition that determined a
specific path to follow.
Indicates additional
Annotation
information about a step in
(Comment) the algorithm.
5.4 The Basic Symbols in Flowchart
SEQUENTIAL STRUCTURE
SELECTION STRUCTURE