Top Banner
22

Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Dec 16, 2015

Download

Documents

Sabina Simmons
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.
Page 2: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Introduction to AlgorithmSession 1

Course : T0974-Algorithm & Object-Oriented Programming IYear : 2011

Page 3: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara University

3

Learning Outcome

After taking this course, students should be expected to explain and discuss their own

Algorithms.

Page 4: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Lecture Outline

• Definition of Algorithm• Characteristics of Algorithm• Programming Language• Algorithm Expression• Pseudocode• Flowchart• NS Diagram

Bina Nusantara University 4

Page 5: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Algorithm Definition

• A precise rule (or set of rules) specifying how to solve some problemwordnetweb.princeton.edu/perl/webwn

• A procedure used to solve a mathematical or computational problem or to address a data processing issue. In the latter sense, an algorithm is a set of step-by-step commands or instructions designed to reach a particular goal. www.colorado.edu/geography/gcraft/gloss/glossary.html

Bina Nusantara University 5

Page 6: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Example

• Sorting. This algorithm is used to arrange of items or number according of its size.

– Input : a set of positive numbers (a1, a2, a3, …, an)

e.g. 5, 3, 4, 2, 1

– Output: a set of arranged numbers (a’1, a’2, a’3, …, a’n)

e.g. 1, 2, 3, 4, 5• Example of problems which solved using an Algorithm.

– Human Genome Project to identify 100.000 of human DNA genes.

– Search Engines (Yahoo, Google, etc)– GPS Tracking System.

Bina Nusantara University 6

Page 7: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Characteristics of Algorithm

• Input• Output• Definitness• Finiteness• Effectiveness

Bina Nusantara University 7

An algorithm should have the following five characteristics :

Page 8: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Programming Language• A sequence of instructions that a computer can

interpret and execute) "the program required several hundred lines of code” --wordnetweb.princeton.edu

• Instruction is a line of code written as part of a computer program –wordnetweb.princeton.edu

• Example :– COBOL (Common Business Oriented Language)– FORTRAN (FORmula TRANslation)– Ada (Ada Lovelace)– C– C++ (C Based Object-Oriented Programming Languange)– Java

Bina Nusantara University 8

Page 9: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Expressing an Algorithm

Expressing an Algorithm can be expressed using a method below :

• Pseudocode• Flowchart• NS Diagram

Bina Nusantara University 9

Page 10: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Psedocode

Pseudocode (pronounced SOO-doh-kohd) is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language.—WhatIs.com

Bina Nusantara University 10

Page 11: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Pseudocode

BEGIN

Hold up the phone

WHILE not dialPress dial

button

WHILE not connected

Waiting dial

IF connected THENWHILE not

finishTalking

Hold down the phone

ENDBina Nusantara University 11

Example of phone calls using pseudocode.

Page 12: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Pseudocode

BEGIN

Number = Input NumberResult = Number % 2

IF Result = 0THEN Print “The number is even

number”ELSE

THEN Print “The number is odd number”

ENDBina Nusantara University 12

Example of Pseudocode to determine odd-even number

Page 13: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Flowchart

• Schematic representation of process or algorithm.

• Schematic is a illustration of system in simplified or symbolic form.

Bina Nusantara University 13

Page 14: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

Flowchart

• Notasi Proses, Data Entry

• Selection :• Flow Lines :• Input/Output:• Stop Notation :

RECTANGLE

DIAMOND

Start

PARALLELOGRAM

CIRCLE

END

Every algorithm process is usually starts from

And ends by

Page 15: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

FlowchartExample of Phone Calling Flowchart

Hold up the phone

Press dial button

Waiting

Start

Dialing

No

Yes

ConnectedNo

Yes

Talking

Finish

No

Yes

Hold down the phone

END

Page 16: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

FlowchartExample of determining odd-even number

Start

Input Number

Number % 2

Print “Odd Number” Print “Even Number”

01

END

Page 17: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

NS Diagram

• NS Diagram is a graphical illustration of structured progamming design.

• Its method is by drawing a table for illustrating an algorithm.

• Founded in 1972 by Isaac Nassi & Ben Shneiderman.

• Known as structograms.

Page 18: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

NS Diagram

• Process notation :

• Selection notation:

• Loop notation :– WHILE

– DO-WHILE

Proses

Kondisi

Betul Salah

Kondisi BelumTerpenuhi

Proses

KondisiBelum Terpenuhi

Proses

Page 19: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

NS Diagram

Example of Phone Calling process using NS Diagram

Hold up the phone

Dialing?

Press dialbutton

Finish?

Talking

Hold down the phone

Page 20: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

NS Diagram

Insert number

Print “EvenNumber”

Number % 2

Equal to 0 Equal to 1

Print “OddNumber”

Example of NS Diagram to determine odd-even numbers

Page 21: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Did you know ?

• The word "algorithm" comes from the name of the ninth-century Persian mathematician Mohammed al-Khowarizmi. He wrote a widely read book entitled Kitab al jabr w'al-muqabala (Rules of Restoration and Reduction) in the year of 825. This book describes many procedures for the manipulation of decimal numbers.

• The word was translated into Latin in the twelve century as “Algoritmi de numero Indorum“ or “Algoritmus on the numbers of the Indians“

Bina Nusantara University 21

Page 22: Introduction to Algorithm Session 1 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2011.

Bina Nusantara

Referensi• Introduction to Algorithms. 2ed. Cormen. 2002. p5-13• Introduction to Java Programming. 8ed. Liang. 2011.

p29-30• Algorithm. http://en.wikipedia.org/wiki/Algorithm• Pseudocode. http://en.wikipedia.org/wiki/Pseudocode• Flowchart. http://en.wikipedia.org/wiki/Flowchart• NS Diagram. http://en.wikipedia.org/wiki/NS_Diagram