Algorithm is sequence of well-defined steps to solve a problem/sequence of steps arranged in a specific logical order which produces a solution for a problem
Good algorithm requirement:
Input
Output
Generality
Correctness
Finiteness
INPUT is conceivable that an algorithm may have no input. However, such algorithms are trivial and quite rare
OUTPUT is an algorithm that does not produce anything is worthless
GENERALITY is it must be general (can be used for different inputs)
CORRECTNESS is It must be correct and must solvetheproblem for which it is designed
FINITENESS is it must execute its step and terminate in finite time
to represent algorithm:
IPOChart
Pseudocode
Flowchart
Find the square of a number INPUT : Number
PROCESS : Calculate Square
OUTPUT: Square
Calculate and display the average of three marks INPUT: mark1, mark2, mark3
PROCESS: calculateaverage
OUTPUT: average
Calculate the area of a circle INPUT: radius
PROCESS: calculateAreaCircle
OUTPUT: AreaCircle
RM200 per night, service charge is 15%, determine total amount:
PSEUDOCODE is writtenstatement of an algorithm using asemiformal language with limitedvocabulary
The main purpose of using pseudocode is to define the procedural logic of an algorithm in a simple, easy-to-understand for its readers, who may not be proficient in computer programming language
In order to succeed in accomplishing its objectives, a pseudocode must:
1. Have limitedvocabulary
2. Easy to learn
3. Produce simple, English-like narrative notation
4. Capable of describing all algorithms, regardless of their complexity
General format for pseudocode:
START
DECLARE Variable1, Variable2,..... INPUT/READ/ENTER/GET....(input) Formula/Condition.... (process) OUTPUT/DISPLAY/PRINT....(output)
END
PROBLEM STATEMENT 1: Find the square of a number
START DECLARE Number, Square
INPUT Number
Square Number×Number
PRINT Square
END
Calculate and display the average of three marks
START DECLARE Mark1, Mark2, Mark3, Average
INPUT Mark1, Mark2, Mark3
Average (Mark1 + Mark2 + Mark3)/3
PRINT Average
END