Analysis of Algorithms

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Math 6200 / Data Analyis

1
]

Module 4-Algorithm Analysis

At the end of this module, you as and are expected t0:


1. Define an algorithm analysis.
2. Distinguish different case time for algorithms.
3. Identify the cost models for different algorithms.

  Algorithm Analysis- refers to the process of deriving estimates for the time and space needed to
execute the algorithm

Time needed to execute an algorithm is a function of the input.

best-case time-minimum time to execute the algorithm

worst-case time-maximum time needed to execute the algorithm

average-case time-average time to execute the algorithm

Analysis of algorithms
For looking up a given entry in a given ordered list, both the binary and the linear search algorithm (which
ignores ordering) can be used. The analysis of the former and the latter algorithm shows that it takes at
most log2(n) and n check steps, respectively, for a list of length n. In the depicted example list of length 33,
searching for "Morin, Arthur" takes 5 and 28 steps with binary (shown in cyan) and linear (magenta) search,
respectively.

Course Module
Graphs of functions commonly used in the analysis of algorithms, showing the number of
operations N versus input size n for each function
In computer science, the analysis of algorithms is the process of finding the computational complexity of
algorithms – the amount of time, storage, or other resources needed to execute them. Usually, this
involves determining a function that relates the length of an algorithm's input to the number of steps it
takes (its time complexity) or the number of storage locations it uses (its space complexity). An algorithm
is said to be efficient when this function's values are small, or grow slowly compared to a growth in the
size of the input. Different inputs of the same length may cause the algorithm to have different behavior,
so best, worst and average case descriptions might all be of practical interest. When not otherwise
specified, the function describing the performance of an algorithm is usually an upper bound, determined
from the worst case inputs to the algorithm.

The term "analysis of algorithms" was coined by Donald Knuth.[1] Algorithm analysis is an important part of
a broader computational complexity theory, which provides theoretical estimates for the resources needed
by any algorithm which solves a given computational problem. These estimates provide an insight into
reasonable directions of search for efficient algorithms.

In theoretical analysis of algorithms it is common to estimate their complexity in the asymptotic sense, i.e.,
to estimate the complexity function for arbitrarily large input. Big O notation, Big-omega
notation and Big-theta notation are used to this end. For instance, binary search is said to run in a number
of steps proportional to the logarithm of the length of the sorted list being searched, or in O(log(n)),
colloquially "in logarithmic time". Usually asymptotic estimates are used because
different implementations of the same algorithm may differ in efficiency. However the efficiencies of any
two "reasonable" implementations of a given algorithm are related by a constant multiplicative factor
called a hidden constant.

Exact (not asymptotic) measures of efficiency can sometimes be computed but they usually require certain
assumptions concerning the particular implementation of the algorithm, called model of computation. A
model of computation may be defined in terms of an abstract computer, e.g., Turing machine, and/or by
postulating that certain operations are executed in unit time. For example, if the sorted list to which we
apply binary search has n elements, and we can guarantee that each lookup of an element in the list can
be done in unit time, then at most log2 n + 1 time units are needed to return an answer.

Cost models

Time efficiency estimates depend on what we define to be a step. For the analysis to correspond usefully
to the actual execution time, the time required to perform a step must be guaranteed to be bounded
above by a constant. One must be careful here; for instance, some analyses count an addition of two
numbers as one step. This assumption may not be warranted in certain contexts. For example, if the
numbers involved in a computation may be arbitrarily large, the time required by a single addition can no
longer be assumed to be constant.

Two cost models are generally used:[2][3][4][5][6]


Math 6200 / Data Analyis
3
]

 the uniform cost model, also called uniform-cost measurement (and similar variations), assigns a


constant cost to every machine operation, regardless of the size of the numbers involved
 the logarithmic cost model, also called logarithmic-cost measurement (and similar variations),
assigns a cost to every machine operation proportional to the number of bits involved

The latter is more cumbersome to use, so it's only employed when necessary, for example in the analysis
of arbitrary-precision arithmetic algorithms, like those used in cryptography.

A key point which is often overlooked is that published lower bounds for problems are often given for a
model of computation that is more restricted than the set of operations that you could use in practice and
therefore there are algorithms that are faster than what would naively be thought possible. [7]

Run-time analysis
Run-time analysis is a theoretical classification that estimates and anticipates the increase in running
time (or run-time) of an algorithm as its input size (usually denoted as n) increases. Run-time efficiency is a
topic of great interest in computer science: A program can take seconds, hours, or even years to finish
executing, depending on which algorithm it implements. While software profiling techniques can be used
to measure an algorithm's run-time in practice, they cannot provide timing data for all infinitely many
possible inputs; the latter can only be achieved by the theoretical methods of run-time analysis.

Shortcomings of empirical metrics

Since algorithms are platform-independent (i.e. a given algorithm can be implemented in an


arbitrary programming language on an arbitrary computer running an arbitrary operating system), there
are additional significant drawbacks to using an empirical approach to gauge the comparative
performance of a given set of algorithms.

Take as an example a program that looks up a specific entry in a sorted list of size n. Suppose this
program were implemented on Computer A, a state-of-the-art machine, using a linear search algorithm,
and on Computer B, a much slower machine, using a binary search algorithm. Benchmark testing on the
two computers running their respective programs might look something like the following:

Computer A run-
Computer B run-time
n (list size) time
(in nanoseconds)
(in nanoseconds)
16 8 100,000
63 32 150,000
250 125 200,000
1,000 500 250,000

Course Module
References and Supplementary Materials
Books and Journals
1. Sanjiv Ranjan Das; 2016; Data Science :Theories ,Models ,Algorithms and Analytics ; S.
R. Das
2. Richard Johnsonbough; 2005; Introduction to Discrete Mathematics; Pearson
Education South Asia Pacific

You might also like