Upload
sabina-simmons
View
224
Download
3
Tags:
Embed Size (px)
Citation preview
Introduction to AlgorithmSession 1
Course : T0974-Algorithm & Object-Oriented Programming IYear : 2011
Bina Nusantara University
3
Learning Outcome
After taking this course, students should be expected to explain and discuss their own
Algorithms.
Lecture Outline
• Definition of Algorithm• Characteristics of Algorithm• Programming Language• Algorithm Expression• Pseudocode• Flowchart• NS Diagram
Bina Nusantara University 4
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
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
Characteristics of Algorithm
• Input• Output• Definitness• Finiteness• Effectiveness
Bina Nusantara University 7
An algorithm should have the following five characteristics :
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
Expressing an Algorithm
Expressing an Algorithm can be expressed using a method below :
• Pseudocode• Flowchart• NS Diagram
Bina Nusantara University 9
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
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.
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
Flowchart
• Schematic representation of process or algorithm.
• Schematic is a illustration of system in simplified or symbolic form.
Bina Nusantara University 13
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
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
Bina Nusantara
FlowchartExample of determining odd-even number
Start
Input Number
Number % 2
Print “Odd Number” Print “Even Number”
01
END
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.
Bina Nusantara
NS Diagram
• Process notation :
• Selection notation:
• Loop notation :– WHILE
– DO-WHILE
Proses
Kondisi
Betul Salah
Kondisi BelumTerpenuhi
Proses
KondisiBelum Terpenuhi
Proses
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
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
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
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