Basic Algoritm
Basic Algoritm
Basic Algoritm
3. Algorithm analysis
4. Implementation
5. Testing
6. [Maintenance]
1. Problem Definition
• What is the task to be accomplished?
Calculate the average of the grades for a given student
Understand the talks given out by politicians and translate them in
Chinese
• Problems?
Experimental Approach
• It is necessary to implement and test the algorithm in order to
determine its running time.
• Experiments can be done only on a limited set of inputs, and may
not be indicative of the running time for other inputs.
• The same hardware and software should be used in order to
compare two algorithms. – condition very hard to achieve!
Algorithm Description
• How to describe algorithms independent of a programming
language
• Pseudo-Code = a description of an algorithm that is
more structured than usual prose but
less formal than a programming language
• (Or diagrams)
• Example: find the maximum element of an array.
Algorithm arrayMax(A, n):
Input: An array A storing n integers.
Output: The maximum element in A.
currentMax A[0]
for i 1 to n -1 do
if currentMax < A[i] then currentMax A[i]
return currentMax
Pseudo Code
• Expressions: use standard mathematical symbols
use for assignment ( ? in C/C++)
use = for the equality relationship (? in C/C++)
• Methods
calls: object method(args)
returns: return value
• Use comments
• Instructions have to be basic enough and feasible!
Example
Algorithm arrayMax(A, n):
Input: An array A storing n integers.
Output: The maximum element in A.
currentMax A[0]
for i 1 to n -1 do
if currentMax < A[i] then
currentMax A[i]
return currentMax