2080 11

CSC211 ยท 2080 ยท 5 marks

What is asymptotic analysis? Explain theta notation with example.

What is asymptotic analysis? Explain theta notation with example. [5]

Data Structures and AlgorithmsChapter 1: Introduction to Data Structures & AlgorithmsAsymptotic notations and common functions

Quick answer

Asymptotic analysis of an algorithm refers to defining the mathematical framing of its run-time performance. It is a technique used to evaluate the performance of an algorithm in terms of input size, without measuring the actual running time.

Asymptotic Analysis and Theta Notation

Asymptotic Analysis

Using asymptotic analysis, we can conclude three scenarios of an algorithm:

CaseDescription
Best CaseMinimum time required for program execution
Average CaseAverage time required for program execution
Worst CaseMaximum time required for program execution

Asymptotic analysis helps us compare algorithms independently of machine, language, or implementation details.


Theta Notation (ฮ˜-Notation)

Theta notation is used to define the tight bound (both upper and lower bound) of an algorithm's running time. It represents the average case complexity.

Definition

A function f(n) is said to be ฮ˜(g(n)) if there exist positive constants c1, c2, and n0 such that:

$$c_1 \cdot g(n) \leq f(n) \leq c_2 \cdot g(n) \quad \text{for all } n \geq n_0$$

This means:

  • g(n) is both an upper bound and a lower bound for f(n)
  • f(n) grows at the same rate as g(n)

Graphical Representation

f(n) is sandwiched between c1*g(n) and c2*g(n)

  |        c2*g(n)
  |       /
  |      / f(n)
  |     /
  |    / c1*g(n)
  |___/________________
              n0       n -->

Example

Let f(n) = 2n + 3

We want to show that f(n) = ฮ˜(n), i.e., g(n) = n.

We need to find c1, c2, and n0 such that:

$$c_1 \cdot n \leq 2n + 3 \leq c_2 \cdot n$$

Finding c2 (upper bound):

$$2n + 3 \leq c_2 \cdot n$$

For n >= 1: $$2n + 3 \leq 2n + 3n = 5n$$

So c2 = 5 works.

Finding c1 (lower bound):

$$c_1 \cdot n \leq 2n + 3$$

Clearly: $$2n \leq 2n + 3$$

So c1 = 2 works.

Result:

$$2n \leq 2n + 3 \leq 5n \quad \text{for all } n \geq 1$$

Therefore, f(n) = 2n + 3 = ฮ˜(n) with c1 = 2, c2 = 5, n0 = 1.


Key Points

  • Theta notation gives an exact asymptotic behavior
  • If f(n) = ฮ˜(g(n)), then f(n) = O(g(n)) AND f(n) = ฮฉ(g(n))
  • It is the most precise of the three asymptotic notations
  • Example: Linear search has ฮ˜(n) average case complexity

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.