Structure of Algorithm
Structure of Algorithm
STRUCTURE OF ALGORITHM
STRUCTURE on WRITING an
ALGORITHM
Descriptive
Flowchart
Pseudo code
The Descriptive Notation
• Descriptive type algorithms mean algorithms written in everyday human language (for
example, Indonesian or English) and in the form of sentences.
• Each step of the algorithm is described in one or more sentences.
• For example, the algorithm determines the largest number of the following 3 numbers:
Another example
Calculates the average of three pieces of data
Algorithm with Indonesian language structure:
1) Baca bilangan a, b, dan c
2) Jumlahkan ketiga bilangan tersebut
3) Bagi jumlah tersebut dengan 3
4) Tulis hasilnya
The Pseudo code Notation
• Pseudo means imitation and code means code that is linked to instructions written in
computer language (programming language code).
• When freely translated, pseudocode means imitation of programming language code.
• Below is an example of an algorithm determine the largest of three numbers written
in pseudocode form.
Another Pseudo-Code Example
Uses:
To design a program
To represent the program
a. Relationship
Flowcharts can provide an effective, clear and
concise description of logical procedures. Clear
graphic presentation techniques will be better
than textual descriptions, especially in
presenting complex logic.
Mengapa Flowchart
b. Analysis
With a clear disclosure in the model or chart,
readers can easily see problems or focus
attention on certain areas of the information
system.
Mengapa Flowchart
c. Communication
Because the symbols used follow a certain
standard that has been generally accepted,
flowcharts can be very effective tools in
communicating the logic of a problem or in
documenting that logic.
Symbols of Flowchart
Symbols of Flowchart (2)
Symbols of Flowchart (3)
Symbols of Flowchart (4)
Symbols of Flowchart (5)
Example of Flowchart
Problem:
Find the Area of a Rectangle
Algorithm:
1. Enter length (p)
2. Enter the width (l)
3. Area (L),
that is, the length multiplied by width
4. Area (L)
Example of Flowchart
Problem:
Determine odd numbers
or even numbers
STRUKTUR ALGORITMA
The Basic Structure of
The Algorithm
1. Sequential
2. Selection
3. Looping/Iteration
1. Sequential
exit
Struktur Seleksi/Pemilihan
exit
Examples of Selection or Branching Structure when making
decisions include if there are different discounts based on the
number of items to be purchased
For
While - do
Repeat - Until
Repeat
………………..
false therms to instructions list
stop ? ………………...
Until (therms)
true
Looping Structure
Contoh : Contoh :
Algoritma Cetak_Angka Algoritma Cetak_Angka
{mencetak 1, 2, .., 8 ke piranti keluaran} {mencetak 1, 2, .., 8 ke piranti keluaran}
Deklarasi : Deklarasi :
k: integer k: integer
Deskripsi : Deskripsi :
k 1 {inisialisasi} k 1 {inisialisasi}
while k <= 8 do repeat
write (k) write (k)
k k + 1 k k+1
endwhile until k > 8
PRACTICE YOUR SELVES
1. Create an Algorithm to check a positive or negative number!
2. Create an algorithm to display the following series of numbers:
1
2
3
4
5
6
PRACTICE YOUR SELVES
3. The following algorithm is known:
Dictionary :
i, m : integer
Algorithm :
i=0
m=0
while i < 9 then
m= i*i
cetak m
i=i+1
endwhile.
Write the output that the algorithm produces above!
References
Jajat Sudrajat, PENGANTAR ALGORITMA DAN IMPLEMENTASI BAHASA PASCAL,
http://www.google.co.id/url?sa=t&rct=j&q=syarat%20algoritma%20yang
%20baik&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F
%2Fyusufhdc.edublogs.org%2Ffiles%2F2010%2F01%2FPENGANTAR-
ALGORITMA_adzet.ppt&ei=K2-FTryKEOqtiQfYuqCSDw&usg=AFQjCNFR-
bfs2ySV6zumBAvRI1tOwM-pvw&cad=rja