Академический Документы
Профессиональный Документы
Культура Документы
Algorithms Design
BITS Pilani
Hyderabad Campus
Course Objectives
No Objective
CO1 Introduce mathematical and experimental techniques to analyze algorithms
CO2 Introduce linear and non-linear data structures and best practices to choose
appropriate data structure for a given application
CO3 Teach various dictionary data structures (Lists, Trees, Heaps, Bloom filters) with
illustrations on possible representation, various operations and their efficiency
CO4 Exposes students to various sorting and searching techniques
CO5 Discuss in detail various algorithm design approaches ( Greedy method, divide and
conquer, dynamic programming and map reduce) with appropriate examples, methods
to make correct design choice and the efficiency concerns
CO6 Introduce complexity classes , notion of NP-Completeness, ways of classifying
problem into appropriate complexity class
C07 Introduce reduction method to prove a problem’s complexity class.
LO1 Describe various fundamental and advanced data structures, their properties, algorithm
design techniques and various means of evaluating algorithms
L02 Demonstrate the ability to evaluate algorithms, to select from a range of possible options, to
provide justification for that selection, and to implement the algorithm in a particular
context.
LO3 Solve problems using Algorithms for Linear and Non-Linear Data Structures
LO4 Explain with a practical example, each of the algorithm design strategies (greedy, divide-
and-conquer, dynamic programming and map-reduce)
LO6 Relate the real-world problems to known data structures and algorithms leading to the
recommend appropriate solutions in representation and implementation.
LO8 Classify problems into complexity classes P and NP and to prove hardness of problems
4/2/2019 Data Structures and Algorithm Design Page 4
Evaluation Scheme
DSAD 05 25 30 40 100
problem
algorithm
INPUT
OUTPUT
DEFINITENESS ALGORITHM
EFFECTIVENESS FINITENESS
• Finiteness:
– An algorithm must terminate after finite number of steps.
• Definiteness:
– The steps of the algorithm must be precisely defined. Each instruction must be
clear and unambiguous.
• Effectiveness:
– The operations of the algorithm must be basic enough to be put down on pencil
and paper.
• Input-Output:
– The algorithm must have certain(zero or more) initial and precise inputs, and
outputs that may be generated both at its intermediate and final steps.
• SPACE
• TIME EFFICENCY
• SPACE
• Program space
• Data space
• Stack space
• TIME EFFICENCY
• Speed of computer
• Choice of programming language
• Computer used
• Choice of algorithm
• Number(size) of inputs
• Experimental Analysis
– Write a program implementing the algorithm
– Execute the program on various test inputs and record the actual time
spent.
– Use system calls (Ex: System.currentTimeMillis() ) to get an accurate
measure of the actual running time.
– Implementation is a must.
• Analytical Model
– High level description of the algorithm.
– Takes into account all possible inputs.
– Allows one to evaluate the efficiency of any algorithm in a way that is
independent of the hardware and the software environment
• Expressions
– Use standard mathematical symbols to describe numeric and Boolean
expressions.
– Uses ← for assignment.(= in Java)
– Use = for the equality relationship.(== in Java)
• Method declaration
– Algorithm name(param1,param2…)
• Method returns: return value
• Control flow
– if … then … [else …]
– while … do …
– repeat … until …
– for … do …
– Indentation replaces braces
4/2/2019 Data Structures and Algorithm Design Page 17
Primitive Operations
Algorithm arrayMax(A, n)
currentMax ←A[0]
for i ← 1 to n - 1 do
if currentMax <A[i] then
currentMax ← A[i]
return currentMax
OR
CONSTANT 1
LOGARITHMIC Log N
LINEAR N
N Log N -
QUADRATIC N2
CUBIC N3
EXPONENTIAL 2N
FACTORIAL N!
• Example
• 2n+10 is O(n)
ie.
2n+10 <=c*n
10/n <=(c-2)
10/c-2 <=n
n >=10/(c-2)
ie .If c=3,n=10
https://rechneronline.de/function-graphs/
• Example
• 5/x is O(1/x)
• 5/x<=c*1/x
• c>=5 for x>=1
• Example:
• The function n2 is not O(n)
– n2 cn
– nc
– The above inequality
cannot be satisfied since c must
be a positive constant
and n max{n1,n2}
– 5n^2>=c.n
– c.n<=5n^2
– c<=5n
– If n=1,c<=5
– 5*1<=4*1 hence the proof.
– 5n^2>=c.n
– c.n<=5n^2
– c<=5n
– If n=1,c<=5
– 5*1<=4*1 hence the proof.
• Prove that f(n) is (n^2)
• f(n) is o(g(n)) (or f(n) ∈ o(g(n))) if for any real constant c > 0,
there exists an integer constant n0 ≥ 1 such that
– f(n) < c ∗ g(n) for every integer n ≥ n0.
• f(n) is ω(g(n)) (or f(n) ∈ ω(g(n))) if for any real constant c > 0,
there exists an integer constant n0 ≥ 1 such that
• f(n) > c * g(n) for every integer n ≥ n0.
• 12n2 + 6n is o(n3 )
• 4n+6 is o(n2 )
• 4n+6 is (1)
• 2n9 +1 is o(n 10)
• n 2 is (log n)