Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Course : Introduction to Programming

Effective Period : September 2018

Introduction to Algorithm
Session 01
Learning Objectives
At the end of this meeting is expected that students will
be able to explain how does the algorithm work

Bina Nusantara 2
Outline
• Definition of Algorithm
• Programming Language
• Algorithm Expression
• Pseudocode
• Flowchart
• NS Diagram
Algorithm Definition
• What is an algorithm?
A set of detailed, unambiguous and ordered
instructions developed to describe the progress
necessary to produce the desired output from a given
input

Bina Nusantara University 4


The Usage of Algorithm
• A specific algorithm is built for a specific needs
Algorithm Example
• Sorting: this algorithm is used to arrange of string or
number according to the order priority
(ascending/descending)
– Input : a set of positive numbers. Ex : 5, 3, 4, 2, 1
– Output : a set of arranged numbers. Ex : 1, 2, 3, 4, 5
(Descending)
• Example of problems which solved using an Algorithm.
– Finding a nearby driver (Grab, Go-jek, Uber)
– Search Engines (Yahoo, Google, etc)
– Face tracking and recognition (Facebook photo
uploader)

Bina Nusantara University 6


Characteristics of Algorithm
An algorithm should have the following five characteristics :
• Input
• Output
• Definiteness
• Finiteness
• Effectiveness

Bina Nusantara University 7


Programming Language
• Creation of program that is executable by a computer and
performs the required tasks
• The high-level languages are English-like and easy to learn
and program
• The following well-known high-level languages:
– COBOL (Common Business Oriented Language)
– FORTRAN (FORmula TRANslation)
– Pascal
– C
– C++ (an object-oriented language, based on C)
– 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

Bina Nusantara University 10


Some Keywords That Should be
Used
• Input
Read, Get, Input, Baca, or Key-In
• Output
Print, Write, Put, Output, or Display
• Looping
DOWHILE and ENDDO, REPEAT and UNTIL, WHILE
• Selection
IF and ENDIF, CASE and ENDCASE
• Compute
Compute, Calculate, Add, Sum, Multiply, Increment
• Initialize or Store Value to An Identifier
Set, Initialize, Store, Save, =

Bina Nusantara University 11


Pseudocode
Example of Pseudocode to determine odd-even number
BEGIN
Number = Input
Number
Result = Number % 2
IF Result = 0
THEN Print “The
number is even
number”
ELSE
THEN Print “The
number is odd
number”
END

Bina Nusantara University 12


Flowchart
• Schematic representation of process or algorithm.
• Schematic is a illustration of system in simplified or
symbolic form.

Bina Nusantara University 13


Flowchart Symbols

Bina Nusantara University 14


Flowchart
Example of determining odd-even number
Start

Input Number

Number % 2
1 0
Print “Odd Print “Even
Number” Number”

END
Bina Nusantara University 15
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 University 16


NS Diagram

Process

• Process notation :

Condition False
True
• Selection notation:

• Loop notation :
Unfulfilled
– WHILE Condition Process

– DO-WHILE Process
Unfulfilled
Condition
Bina Nusantara University 17
NS Diagram
Example of NS Diagram to determine odd-even numbers

Insert number

Number %Equal
2 to 1
Equal to 0

Print “Even Print “Odd


Number” Number”

Bina Nusantara University 18


Exercise
1. From the following pseudocode example of grade
average calculation, create the flowchart and NS
Diagram
BEGIN
Set total to zero
Set grade_counter to one

While grade_counter is less than or equal to ten


Input the next grade
Add the grade into the total
Set the class_average to the total divided by ten

Print the class_average


END

Bina Nusantara University 19


Exercise
2. Using the Pseudo-code and flowchart, create:
• an algorithm to calculate a triangle area!
• an algorithm to change second into hour and minute
unit!
• an algorithm to accept three numbers and find max,
min, and average number!
• an algorithm to calculate a circle area!
• an algorithm to calculate rectangle circumference!

Bina Nusantara University 20


References
• Lesley Anne Robertson, 2006, Simple program design :
a step by step approach, Vol.05, Course Technology.
Chapter 1 and 2.

Bina Nusantara University 21

You might also like