This action might not be possible to undo. Are you sure you want to continue?

Budi Hartono, ST, MPM Simulation Laboratory, UGM

**Process, Instruction & Action
**

**Algorithm = logical sequences
**

The instruction t0 = state - before the action action t1 = state - after

Example

A

B

A ACTION

B

t0

t1

t0 : A contains yellow, B contains blue 1. Pour the blue water to C 2. Pour the yellow water to B 3. Pour the blue water to A t1 : A contains blue, B contains yellow

Algorithm Exchange_the_contents

**Top-down design
**

General

1 10

**First, then go details
**

2 15 3 5 4 17 5 2 Order from the smallest value N=5

- Iterations N-1 times - Find the smallest - Position exchange

1 10 Pass k = 1

2 15

3 5

4 17

5 2

N=5

Find the smallest value, from N = 1 to N = 5 1 10 2 15 3 5 4 17 5 2

Result, min = 2

Exchange the location 1 2 2 15 3 5 4 17 5 10

1 2 Pass k = 2

2 15

3 5

4 17

5 10

N=5

Find the smallest value, from N = 2 to N = 5 1 2 2 15 3 5 4 17 5 10

Result, min = 5

Exchange the location 1 2 2 5 3 15 4 17 5 10 And so on

**The initial & final states:
**

**T0 : random sequence of values
**

Algorithm Data_Order

T1 : ordered sequence of values

Where:

Algorithm Data_Order

Given N random data. Order them so that data#1 < data #2 < … < data #N Description: For pass k = 1,2, …, N-1 1. Find the smallest value (min) from k = 1 to k = N 2. Exchange min with data#k

START k = k+1 1. Find min

2. Position min @ k

K=4 ? YES STOP

1. Find min • Not detail enough • Must be refined Refining Step-1 1.1 Assume data #k is the min (temporary) 1.2 compare min with data #j; where j =(k+1), (k+2), .. , N if data #j < min, then data #j becomes the new min Refining Step-1.2 1.2.1 For j = (k+1), (k+2), …, N do: if data #j < min then data #j becomes the new min

2. Position min @ k Refining: 2.1 put data #k to a temporary place (temp) 2.2 put the min on the place of the data #k (formerly) 2.3 put the temp on the min (formerly)

**The final algorithm
**

Algorithm Data_Order

Given N numbers of random data. Make an order of data so that: data#1 < data #2 < … < data #N Description:

For pass k = 1,2, …, N-1, do the following: {1. Find the smallest value (min) from k = 1 to k = N} 1.1 assume that data #k is the min 1.2 For j = (k+1), (k+2), …, N do: if data #j < min then data #j becomes the new min {2. Exchange min with data#k } 2.1 put data #k to a temporary place (temp)

2.2 put the min on the place of the data #k (formerly) 2.3 put the temp on the min (formerly)

I leave the flowchart for the next week’s homework

**Basic Structures of Algorithms
**

Sequence Selection Repetition

Basic Structures of Algorithms

Sequence

THE RESULT ?

A1

A1

A2

A3

A3

A2

A

B

A4

A4

C

Basic Structures of Algorithms

Selection

Conditions Recall:

**if data #j < min then data #j = new min The general structure
**

If condition then action

Basic Structures of Algorithms

Selection

Example If

Amir wins the competition then daddy will give him a new car If Malioboro gets a traffic jam then go to Jl. Ahmad Dahlan

Your

example …

Basic Structures of Algorithms

Selection

Another

**structure If condition then
**

action 1

**else action 2 indenting
**

Your

example …

Basic Structures of Algorithms

Repetition

An

advantage of using computers:

Do

**repetitive jobs without getting bored Precision
**

I

promise that I will never forget to do my homework 100 times !!!

Basic Structures of Algorithms

Repetition

**Algorithm Writing_500_sentences Description
**

4. 5. 6. 7. 8.

Write “I promise that I will never forget to do my homework” Write “I promise that I will never forget to do my homework” Write “I promise that I will never forget to do my homework” Write “I promise that I will never forget to do my homework” Write “I promise that I will never forget to do my homework” Write “I promise that I will never forget to do my homework”

… 500

???

Basic Structures of Algorithms

Repetition

**Algorithm Writing_500_sentences Description: sentenceNumber = 0 repeat write “I promise that I will never forget to do my homework”
**

sentenceNumber = sentenceNumber +1

until sentenceNumber = 500

Basic Structures of Algorithms

Repetition

General

Structure

Repeat action Until condition

A combination

Find

a NIM of a student from 500 entries (random) .

- Makna Perayaan Hari Raya Siwaratri
- Ergonomi-Kognitif
- fulltext_765
- pengenalan%20teknologi%20informasi%202
- pengenalan teknologi informasi 1
- pendahuluan
- individual_assignment
- leastsquare
- sequencing
- TIPE DATA
- TEKNIK INFORMASI
- Teknologi INFORMASI
- Teknologi INFORMASI
- tp minggu 3
- minggu2_4
- minggu2_4
- minggu ke 4 -ruang-sampel-dan-kejadian
- tabel 3
- pengantar strategi algoritmik
- metode straight selection
- metode bubble sort
- kronologis
- perubahan ruu pornografi
- penjelasan ruu p edisi 4 september 2008

- intro_2014
- HW02FAQ
- 02 Course Syllabus
- 0000555352
- CSC263 Assignment 1 2014
- Algorithms for Two-dimensional Bin Packing and Assignment Problems - Lodi (1)
- ADA Model Question Paper-1
- [Peter Van Overschee, Bart de Moor (Auth.)] Subs
- An Overview of Autonomous Mobile Robot Path Planning Algorithms
- a STAR ALGO
- Dana_Ron_PhD.pdf
- Rubik's Cube 3x3x3
- tut5
- 50 DynProbit (Montreal2006)
- Untitled
- Ioi Syllabus
- Algoritmos Aleatorios Leer
- Scimakelatex.4800.Dsfs.wf
- Ioi Syllabus
- 10.1.1.103.5278
- 1329389726_A1
- lecture33.ppt
- 5_DSS_Global State.ppt
- An Algorithm for Training Multilayer Perceptron Mlp for Image Reconstruction Using Neural Network Without Overfitting
- fulltext(1)
- Decoupling Journaling File Systems from IPv6 in Courseware
- 05 DS and Algorithm Session 07
- Reflection C
- Studying for and Taking Tests
- 05 DS and Algorithm Session 07

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd