You are on page 1of 39

Decomposition

Logic Algorithm
Prasetyo Wibowo
Politeknik Elektronika Negeri Surabaya
Departement of Informatic and Computer Engineering,
Subject:
1. Fundamental Decomposition
2. Decomposition in Logic
Algorithm

Politeknik Elektronika Negeri Surabaya 2


Logic Algorithm
Fundamental Decomposition
Politeknik Elektronika Negeri Surabaya
Departement of Informatic and Computer Engineering,
4 Pillar of Computational Thinking

Politeknik Elektronika Negeri Surabaya 4


Logic Algorithm
Heuristic
According to the book How to Solve it by
George Polya Heuristic is a specific
strategy in problem-solving that usually
yields a good enough answer, though not
necessarily an optimal one.

Examples include trial and error, using a


rule of thumb or drawing an analogy.

Computational thinking promotes one of


these heuristics to a core practice:
Decomposition.
Politeknik Elektronika Negeri Surabaya 5
Logic Algorithm
Decomposition
• Decomposition is an approach that
seeks to break a complex problem
down into simpler parts that are easier
to deal with.
• Programmers and computer scientists
usually deal with large, complex
problems that feature multiple
interrelated parts.
• While some other heuristics prove
useful some of the time,
decomposition almost invariably helps
in managing a complex problem
where a computerised solution is the
goal.
Politeknik Elektronika Negeri Surabaya 6
Logic Algorithm
Divide-and-conquer strategy
• Decomposition is a divide-and-conquer strategy and sometime seen in
numerous places outside computing.
• Within the realm of CT, you use divide and conquer when the problem facing you
is too large or complex to deal with all at once.
• For example, a problem may contain several interrelated parts, or a particular
process might be made up of numerous steps that need spelling out.
• Applying decomposition to a problem requires you to pick all these apart.

Politeknik Elektronika Negeri Surabaya 7


Logic Algorithm
Sub-problems on Decomposition
• When you use Decomposition, you aim to
end up with a number of sub-problems that
can be understood and solved individually.
• This may require you to apply the process
recursively
• If the problem might be still too complex,
they need to breaking down again, and
again.
• Visually this gives the problem definition a
tree structure.

Politeknik Elektronika Negeri Surabaya 8


Logic Algorithm
Recursion
• Recursion is a technique used to simplify a
problem. It defines the solution to a large,
complex problem in terms of smaller,
simpler problems of the same form as the
original problem. This is a very powerful
idea and one that is heavily used in CS.

Politeknik Elektronika Negeri Surabaya 9


Logic Algorithm
Let’s Try
How to make a breakfast:

Politeknik Elektronika Negeri Surabaya 10


Logic Algorithm
Let’s Try

Politeknik Elektronika Negeri Surabaya 11


Logic Algorithm
Let’s Try
Hand Washing

Politeknik Elektronika Negeri Surabaya 12


Logic Algorithm
Let’s Try

Politeknik Elektronika Negeri Surabaya 13


Logic Algorithm
Let’s Try

Politeknik Elektronika Negeri Surabaya 14


Logic Algorithm
Let’s Try

Politeknik Elektronika Negeri Surabaya 15


Logic Algorithm
Decomposition in Logic Algorithm
Politeknik Elektronika Negeri Surabaya
Departement of Informatic and Computer Engineering,
Look at this
● This flowchart depicts steps to read file
starting from the first character until the end
of file (EoF).
● While doing so, the program will print (output)
each character so long as it is a legal
character and is not null.
● This flowchart is a little bit too complex to
be understood. Therefore we can extract
some of its processes / steps (decompose)
into subroutine (predefined process) and
explain it in another flowchart.

Politeknik Elektronika Negeri Surabaya 17


Logic Algorithm
Predefined Process (Subroutine)
• A Predefined Process symbol is a marker for another process step or series
of process flow steps that are formally defined elsewhere.
• This shape commonly depicts sub-processes (or subroutines in programming
flowcharts).
• If the sub-process is considered "known" but not actually defined in a process
procedure, work instruction, or some other process flowchart or
documentation, then it is best not to use this symbol since it implies a
formally defined process.

Predefined Process

Politeknik Elektronika Negeri Surabaya 18


Logic Algorithm
Look at this
● After extracting some of its
processes (steps) into
subroutine or predefined
process, it is easier to
understand the flowchart.
● Note that each program may
have more than 1
subroutines and each
subroutine should be
defined in another
flowchart.
a subroutine called PutBad
is created

Politeknik Elektronika Negeri Surabaya 19


Logic Algorithm
Typically, pre-defined functions are better. They usually are optimized to operate in
the least amount of time, no matter what the input (they optimize based on input
type and size).

Politeknik Elektronika Negeri Surabaya 20


Logic Algorithm
Let’s Try
Objective:
Display the class average for the
final scores.
The final score is derived from 25%
assignment score, 35% mid-test
score, and 40% post-test score.

Politeknik Elektronika Negeri Surabaya 21


Logic Algorithm
Let’s Try: Algorithm
Objective: Algorithm:
Display the class average for 1. Input total number of student (N)
the final scores. 2. For each student,
The final score is derived from a. Input student’s scores
25% assignment score, 35% b. Calculate the students’ final score
mid-test score, and 40% post- 1. Calculate the class average score
test score. 2. Display the result

Step 2a can be further elaborated, thus


it can be introduced as subroutine.

Politeknik Elektronika Negeri Surabaya 22


Logic Algorithm
Let’s Try: Algorithm
Algorithm (2a. Input student’s scores):
a. Input mid-test score
b. Check validity of mid-test score
c. If not valid, print error message and return to step a
d. Input assignment score
e. Check the validity of assignment score
f. If not valid, print error message and return to step d
g. Input post-test score
h. Check validity of post-test score
i. If not valid, print error message and return to step g

Politeknik Elektronika Negeri Surabaya 23


Logic Algorithm
Let’s Try: Flowchart (Without Using Subroutine)
Flowchart can be seen in this link.

Politeknik Elektronika Negeri Surabaya 24


Logic Algorithm
Let’s Try: Flowchart (Using Subroutine)

Politeknik Elektronika Negeri Surabaya 25


Logic Algorithm
Let’s Try
Calculate average grades

What structure chart of program?

Politeknik Elektronika Negeri Surabaya 26


Logic Algorithm
Let’s Try
Calculate average grades

What structure chart of program?

Politeknik Elektronika Negeri Surabaya 27


Logic Algorithm
Let’s Try
Calculate average grades

What is the input, process, and


output?

Politeknik Elektronika Negeri Surabaya 28


Logic Algorithm
Let’s Try
Calculate average grades

What is the input, process, and


output?

Input: Input grade, Length of grade,


set (i) = 0
Process: calculate Average grade

Output: Display grade from set (i),


display average grade
Politeknik Elektronika Negeri Surabaya 29
Logic Algorithm
Let’s Try
Pseudocode ? Flowchart ?

Politeknik Elektronika Negeri Surabaya 30


Logic Algorithm
Let’s Try
Pseudocode Flowchart

1. acceptGrade
INPUT length, grade

2. printGrade
SET i = 0
IF i < length

3. calculateAverage
AVG = SUM / length

4. END
Politeknik Elektronika Negeri Surabaya 31
Logic Algorithm
Summary
• Decomposition is an approach that seeks to break a complex problem
down into simpler parts that are easier to deal with.
• Predefined Process symbol is a marker for another process step or
series of process flow steps that are formally defined elsewhere

Politeknik Elektronika Negeri Surabaya 32


Logic Algorithm
NEW KNOWLEDGE IS
INCREASING!
Politeknik Elektronika Negeri Surabaya 33
Logic Algorithm
Reference
1. Karl, Beecher. "Computational Thinking: A Beginner's Guide to Problem-Solving and
Programming." Swindon, UK: BCS, The Chartered Institute for IT (2017).
2. CSE 1300 - Introduction to Computing Principles, Kennesaw State University
3. Computer Science (CS) and Computational Thinking (CT) : Pattern Recognition in the AYA
curriculum, Miami University

Politeknik Elektronika Negeri Surabaya 34


Logic Algorithm
Assignment
Create pseudocode and flowchart
with predefined process for:

• How to make a breakfast


• Find the area, circumference,
radius and diameter of a Circle

Politeknik Elektronika Negeri Surabaya 35


Logic Algorithm
Assignment Noted
• Please make an official practice
report today
• The more you practice, the more
you know!

Politeknik Elektronika Negeri Surabaya 36


Logic Algorithm
Assignment Report
• Each individual collects official
reports in PDF form
• The file format is
NRP_FullName_TitleofReport
• Example: 3321600000_Prasetyo
Wibowo_TitleofReport
• No Plagiarism!

Politeknik Elektronika Negeri Surabaya 37


Logic Algorithm
Next week
• We will learn about String. Please read references about it.
• It is strongly encouraged to do self study and self-paced practicum.

Politeknik Elektronika Negeri Surabaya 38


Logic Algorithm
THANK YOU!
Politeknik Elektronika Negeri Surabaya
Departement of Informatic and Computer Engineering,

You might also like