0% found this document useful (0 votes)
59 views

Structure of Algorithm

The document discusses the basic structure of algorithms, which consists of three main parts: the header, dictionary, and description. The dictionary defines variable types, constants, and functions. The description contains the defined steps or actions of the algorithm. Algorithms can be written descriptively in natural language, as pseudocode, or as flowcharts. Flowcharts use standard symbols to visually depict the logic and sequence of steps. Common algorithm structures include sequential, selection/branching, and looping/iteration. Selection structures use conditions to determine which steps or actions to perform, while looping structures repeatedly perform steps until a condition is met.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Structure of Algorithm

The document discusses the basic structure of algorithms, which consists of three main parts: the header, dictionary, and description. The dictionary defines variable types, constants, and functions. The description contains the defined steps or actions of the algorithm. Algorithms can be written descriptively in natural language, as pseudocode, or as flowcharts. Flowcharts use standard symbols to visually depict the logic and sequence of steps. Common algorithm structures include sequential, selection/branching, and looping/iteration. Selection structures use conditions to determine which steps or actions to perform, while looping structures repeatedly perform steps until a condition is met.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

ALGORITHM

STRUCTURE OF ALGORITHM
STRUCTURE on WRITING an
ALGORITHM

Each Algorithm will always consist of three


parts, namely:
Header
Dictionary
Algorithm it’s self (Description)
Header

Header is a part of algorithm text that is used as a


place to define a name by determining whether it
is a program, a procedure, or a function.
Dictionary (Declaration)

Dictionary is part of algorithm that id used as place


to define:
a Type name
a Constant name
a Variable name
a Function name
a Procedure name
Kamus (Deklarasi)
Algorithm (Description)

Algorithms are the core part of an algorithm that contains


defined instructions or action calls.
Notations of 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

Calculates the average of three numbers


Algorithm with pseudo code structure:
1) input (a, b, c)
2) Sum = a+b+c
3) Ave = Sum/3
4) output (Ave)
The Flowchart Notation

• Apart from being in written form, the


algorithm can also be written in the form of
diagrams with arrows to indicate the sequence
of the algorithm steps. Algorithms written
with such symbols are called flowcharts.
• Flowchart is a graphic depiction of the steps
and sequence of procedures of a program
• Now an example is given of the algorithm
determining the largest number out of 3 as
shown earlier.
Flowchart

Uses:
To design a program
To represent the program

So, flowcharts must be able to represent


components in a programming language
Why Flowchart

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

• A sequence consists of one or more "instructions".


• Each instruction is carried out sequentially according to the
order in which it is written; a new instruction can be executed
after the previous instruction has been completed.
Struktur Runtunan
Example of a program that is run using the List (Sequential)
structure
2. Selection

• Selection structure in English (selection) or Branching is an


algorithmic structure that states the selection of steps based on a
condition or decision making.
• The main characteristic of the Branching structure is the form of a
rhombus flowchart (decision).
• In this structure, if the conditions are met then one action will be
carried out and the second action will be ignored.

Conditions are requirements that can be judged to be true or


wrong so that it will give rise to a different 'action'
with different "conditions".
Selection/Branching Structure

Pseudo code notation:


if Terms then
Action {True}
endif {False}

exit
Struktur Seleksi/Pemilihan

Pseudo code notation:


IF Therms THEN
action-1 {true}
ELSE
action-2 {false}
ENDIF

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

Input: item yg akan


dibeli
3. Looping / Iteration

Used for programs whose statements will be


executed over and over. Instructions worked out during
meet a certain condition. If the terms (conditions)
is still fulfilled then the statement (action) will continue
done repeatedly.
Looping Structure

For

Var  begining to end do For varbegining to end


…………….
match or true not-match instructions list
Or ……………..
instructions list false endfor
Looping Structure

While - do

false Common form :


therms
?
While (therms) do
…………..
true
instructions list
…………..
instructions list
Endwhile
Looping Structure

Repeat - Until

instructions list Common form ;

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

You might also like