Professional Documents
Culture Documents
1
Pseudocode
• Made up of :
– Algorithm header – describes alg’s parameters
– Purpose –short stmt about what alg does
– Pre condition – list of any requirements needed before
processing
– Post condition – outcome of the processing
– Body – made up of stmt constructs (seq, selection &
loop) to be executed
– Return – value returned by alg
2
Example of Pseudocode
3
Definations
• Atomic – data that are single, nondecomposable entities.
• Atomic data type – set of atomic data with identical
properties
• Atomic data types – set of values and set of operations
that act on the values
• Data structure – a collection of atomic and composite
data types into a set with defined relationships
• Abstract data type(ADT) – data declaration packaged
together with the operations meaningful for the data type.
The implementation is hiden
4
Abstract Data Type Model
5
Algorithm Efficiency
• On single algorithm for any problem
• One often finds one algorithm more
efficient than the other
• Defined as a function of the number of
elements being processed and the type of
loop being used.
• Format: f(n) = efficiency
6
Algorithm Efficiency
• Linear loops have efficiency of f(n) = n
• Logarithmic loops f(n) = log2 n (Upper bound)
• Nested Loops – 1st determine how many iterations
each loop completes, then find the find the
product.
– Linear logarithmic f(n) = nlog2 n
– Dependent Quadratic f(n) = n(n+1)/2
– Quadratic f(n) = n2
7
Big-O Notation
• Simplification of efficiency sometimes
known as big-O analysis
• Considers the dominant factor in the
derived function as factor determining the
magnitude, expressed as O(n)
• Hence quadratic alg. has efficiency of
O(f(n)) = O(n2 )
8
Big – O Notation
• Can be derived from f(n) using following
steps:
1. Set coefficient of each term to 1
2. Keep largest term in the function and discard
the rest with terms ranked from lowest to
highest.
9
Big – O Ranges
10