Data Structures Introduction
Data Structures Introduction
*
Asymptotic Complexity
⬥ Running time of an algorithm as a function of
input size n for large n.
⬥ Expressed using only the highest-order term in
the expression for the exact running time.
⬧ Instead of exact running time, say Θ(n2).
⬥ Describes behavior of function in the limit.
⬥ Written using Asymptotic Notation.
⬥ 10n2 - 3n = Θ(n2)
⬥ What constants for n0, c1, and c2 will work?
⬥ Make c1 a little smaller than the leading
coefficient, and c2 a little bigger.
⬥ To compare orders of growth, look at the
leading term.
⬥ Exercise: Prove that n2/2-3n= Θ(n2)
asymp - 10
Definition
asymp - 11
Algorithms
Properties of algorithms:
• Input An algorithm has zero or more inputs,
• Output An algorithm produces at least one output.
• Clear and Unambiguous: The algorithm should be clear
and unambiguous
• Definiteness of every step in the computation, Every
fundamental operator in instruction must be defined without any
ambiguity.
• Language Independent: The Algorithm designed must be
language-independent
12
asymp - 12
Algorithms
Properties of algorithms:
• Definiteness of every step in the computation, Every
fundamental operator in instruction must be defined without any
ambiguity.
• Correctness of output for every possible input,
• Finiteness An algorithm must terminate after a finite number
of steps in all test cases. Every instruction which contains a
fundamental operator must be terminated within a finite amount
of time.
• Effectiveness An algorithm must be developed by using
very basic, simple, and feasible operations.
13
asymp - 13
The Growth of Functions
“Popular” functions g(n) are
n.log n, 1, 2n, n2, n!, n, n3, log n
• 1
• log n
• n
• n log n
• n2
• n3
• 2n
• n!
14
asymp - 14