You are on page 1of 16

DATA STRUCTURE

Algorithm Complexity
ALGORITHM
 An algorithm is any well-define
computational procedure that takes some
values or set of values as input and
produces some values or set of values as
output
 As a sequence of computational steps that
transforms the input into output
ALGORITHM COMPLEXITY
 Analyzing an algorithm has come to means
predicting the resources that algorithm requires.
Such as memory, bandwidth but most often it is
computational time that we want to measure.
 Space Complexity: Amount of memory space
required by the algorithm during the course of
its execution.
 Time Complexity: Amount of time that algorithm
takes to execute. This is not really a number of
seconds or any other clock measurement but
rather an approximation of the number of
operations that an algorithm performs.
ANALYZING AN ALGORITHM
 The actual number of operations done for some
specific size of input data set is not very
interesting nor it tells us very much.
 Instead our analysis will determine an equation
that relates the number of operations that an
algo. Performs to size of input (GROWTH RATE)
 We can compare two algorithms by comparing
the rate at which this equation grows.
 There are instances where algo. ‘A’ may take
fewer operations than algo ‘B’ when input size
is very small but many more when input size
gets large.
COMPLEXITY

 For example, let us assume two algorithms A


and
B that solve the same class of problems.
 The time complexity of A is 5,000n, the one for
B is 1.1^n for an input with n elements.
 For n = 10, A requires 50,000 steps, but B
only
3, so B seems to be superior to A.
 For n = 1000, however, A requires 5,000,000
steps, while B requires 2.5*10^41 steps.

You might also like