You are on page 1of 10

MODULE – I

Introduction to Data Structures


Introduction to Data Structures and Algorithms, Analysis of Algorithms,
Asymptotic notations, Time and space trade-off, ADT. Arrays and Lists,
Row/Column major representation of Arrays, Sparse matrix.

 Algorithm: An algorithm is an outline of the steps that a program or any


computational procedure has to take.
 Program: An implementation of an algorithm and it could be in any
programming language.
 Data Structure: Data structure is the way we need to organize the data, so
that it
can be used effectively by the program.

 How an Algorithm is specified: 1) Natural Language


2) Flowchart
3) Pseudocode
 Given some Input Specification and Output Specifications, Multiple
algorithms are possible to solve the problem.

 Characteristics of an algorithm:
 Input: An algorithm should have 0 or more well-defined
inputs.
 Output: An algorithm should have 1 or more well-defined outputs,
and should match the desired output.
 Definiteness: Algorithm should be clear and unambiguous. Each
of its steps and their inputs/outputs should be clear and must
lead to only one meaning
 Finiteness: Algorithms must terminate after a finite number of
steps
 Effectiveness: Should be feasible with the available resources.
 Expectations from a good Algorithm:
 Correctness of the output
 Efficient
 Algorithm Complexity
Suppose X is an algorithm and n is the size of input data, the time
and space used by the algorithm X are the two main factors, which
decide the efficiency of X.
 Space Complexity: Space complexity of an algorithm represents
the amount of memory space required by the algorithm till
its completion
 Time Complexity: Time complexity of an algorithm represents the
amount of time required by the algorithm to run to completion.

 Algorithm Analysis: Efficiency of an algorithm can be analysed at two


different stages, before implementation and after implementation. They
are the following −
Apriori Analysis or Performance Analysis − This is a theoretical
analysis of an algorithm. Efficiency of an algorithm is measured before the
actual implementation of the algorithm(program).
Aposterior Analysis or Performance Measurement– This is an empirical
analysis of an algorithm. The selected algorithm is implemented using
programming language. This is then executed on target computer machine. In
this analysis, actual statistics like running time and space required, are collected.
Advantages of Apriori Analysis?
Independent of speed of computer,
programming language,
expertise of the programmer,
compiler or interpreter
Independent of input size
Same input size of different type
Apriori Alanysis: A combination of 2 ideas:
1. Represent the time(running) taken by the algo as a function of
the size of its input
2. Find out the rate of growth of the function –how fast the
function grows with input size
e.g. f(n)=an2+bn+c growth rate is faster
f(n)=an+b
We only focus on the order of growth of the running time. (we look @
the dominant term in the running time). In the first example it is n2 and in the
second one it is n.
Asymptotic Analysis: It discusses the complexity of an algorithm when the
input size is large.
Asymptotic Notation:
It is a way to describe the characteristics of a function in the limit.

It describes the rate of growth of functions.

Focus on what’s important by abstracting away low-order terms and constant factors

It is a way to compare “sizes” of functions:

This notation gives the tight upper bound of the given function.
Big-O Examples
Example-1 Find upper bound for f(n) = 3n + 8
Solution: f(n)<=c(g(n))

3n + 8 ≤ 4n, for all n ≥ 8


∴ 3n + 8 = O(n) with c = 4 and n0 =8
 Apriori Analysis Example :

Determine the running time of an algorithm with apriori analysis.

Find the time complexity of insertion sort algorithm:

You might also like