classnotes RTX 4070 Ti SUPER · faster-whisper · DeepSeek

5101 - Design & Analysis of Algo

← 5101 - Design & Analysis of Algo

DAA_06 Sep

Date 2026-09-06 Length 1h 25m Words 9,721 Segments 560
⤓ Download transcript (.txt with timestamps) ⤓ Plain transcript (.txt) ⤓ Transcript (.md)

Summary


session: "5101-design-analysis-of-algo/2026-09-06 0000 DAA 06 Sep"

title: "DAA 06 Sep"

date: "2026-09-06 00:00"

duration: "1h 24m"

language: "en"

model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"

parts: 2

transcript_chars: 49884

generated: "2026-11-23T23:37:27+05:30"


DAA 06 Sep

Overview

This class completes the asymptotic-analysis toolkit begun earlier: it recaps insertion sort's cost analysis and quadratic running time, formalizes loop invariants (initialization, maintenance, termination) and applies them to insertion sort and linear search, then defines big O (upper bound) and big omega (lower bound) and their equivalence with theta (Theorem 3.1 from CLRS). It closes by introducing little o and little omega as strict, non-asymptotic bounds used when f(n) and g(n) are not comparable. This sits at the end of the asymptotic-notation block, immediately before divide and conquer and the master theorem / recursion tree methods for recursive algorithms.

Learning outcomes

Core concepts

Insertion sort recap and cost analysis

Two nested loops: start from the second position, compare with the previous one; then third with second and first; fourth with third, second and first; and so on. A loop inside a loop means the complexity will most likely touch order n². Comments impose no cost (not executed at runtime). Among the step costs, the loop/comparison step imposes the high-order complexity: C1 and C4 are maximum, and C4 is much much greater than C1, which is further much greater than all other costs — because C4 has two comparisons (j greater than zero, and current element less than a of j) while the for loop performs only one comparison. This motivates modeling the algorithm by f(n) = a n² + b n + c.

f(n) / T(n) as a quadratic

The function best representing the algorithmic structure is f(n) = a n² + b n + c, a quadratic expression, which primarily imposes a computational complexity of order n² if the term a is positive. The highest-degree term with a positive constant plays the pivotal role in determining theta, big O and big omega, because the complexity shifts toward that term when n is very very large.

Loop invariant

A loop invariant holds if the order of the element / property of the algorithm / output of the algorithm is not affected by the loop — no impact on the actual behavior of the algorithm while different loops run. Three conditions:

If an algorithm holds all three properties, we can say the algorithm is correct; loop invariant is a famous mechanism to check whether an algorithm is correct.

Loop invariant for insertion sort

Start with the second index and initialize the first index as key; a single element is always sorted, so initialization holds the sorting nature even before the algorithm starts. At step 4, the first, second, third, fourth entries are sorted irrespective of which elements are present; after step 3, 3 elements are sorted; after step 2, 2 elements are sorted; after step 6, 6 elements are sorted — the property is maintained even when the loop is not fully executed (maintenance). After full execution we get the sorted result (termination).

Loop invariant for linear search

Target is to identify a key. Initialization: just declaration of the key (we have not identified the element at index one). Maintenance: however far we have gone without achieving the key, there is no chance the element is present in the portion already traversed. Termination: we have achieved the key or not achieved it at all.

Big O notation (upper bound)

For a given known function g(n), we denote big O of g(n). It confirms the worst case — the maximum time the algorithm will require. Theta used two constants c1, c2 with c1 g(n) less than f(n) less than c2 g(n) greater than 0 for some n0; big O confines to the upper bound only: f(n) less than or equal to c g(n) (only one c). It is the half portion of what was done for theta notation. Using big O we can often describe running time merely by inspecting the algorithm's overall structure — e.g., insertion sort's double nested loop immediately gives an order n² upper bound on the worst-case running time.

Sedgewick (SOM series) definition of big O

Suppose f(n) and g(n) are functions defined on the positive integers (n is input size, so of course a positive integer) with the property that f(n) is bounded by some multiplier of g(n) — that multiplier is c — for almost all n (i.e., n beyond n0). That is, there exists a positive constant n0 and a positive number c such that for n greater than n0 we have f(n) less than c g(n).

Big omega notation (lower bound)

The remaining half of theta notation; it identifies the minimum time the algorithm will require. For some c g(n) we assure f(n) will always be greater than this. Definition (given in Corman): f(n) = omega of g(n) if and only if there exists a positive number n0 and a positive number c such that f(n) is greater than or equal to c g(n) for all n greater than n0.

Relation between the three notations (Theorem 3.1)

If f(n) = theta of g(n), then f(n) is big O of g(n) and f(n) is omega of g(n). Conversely, if f(n) is big O of g(n) and f(n) is omega of g(n), then f(n) = theta of g(n). Both directions are true. Theta imposes both bounds (upper and lower), concluding the complexities lying inside; big O is the upper bound; big omega is the lower bound. Theta notation is for average, big O for worst.

Why three separate notations

The same asymptotic bound (e.g., order n² for insertion sort) behaves differently depending on input behavior — least comparisons (best case), in-between comparisons (average), worst case — so best, average and worst cases must be identified to represent all those characteristics. Computational complexity depends on the characteristics of the input data, not only input size: whether the element is at the first position, second, middle or last gives the three cases.

Little o and little omega

The asymptotic upper bound provided by big O may or may not be asymptotically tight; little o is concerned with the tighter/stricter bound. When equality is removed the bound becomes tighter or strict: at no point of time should f(n) and g(n) be comparable (equal). Little o considers g(n) greater than f(n) (g(n) very large / just large). Little omega is the reverse — g(n) much less than f(n); same condition as omega but with no equality sign, so it is a stricter bound and at no point will f(n) equal g(n) or be comparable. Little o and little omega give strict bounds but are not asymptotic bounds, because asymptotic analysis is more keen on how the algorithm performs as n tends towards infinity.

Asymptotic analysis assumptions

Applicable for positive functions on integer input values; theta, big O and big omega are also called asymptotic bounds. In asymptotic analysis there is a restriction that n is very very large and f(n) by g(n) should be equal to 1 when n tends to infinity; if this is violated we go for little o and little omega, but that will not be an asymptotically tighter bound. Asymptotic analysis assumes monotonically increasing behavior: increasing input size cannot decrease computational complexity. n is the number of inputs supplied to the algorithm, so it is a positive integer — never fractional, never negative; c1 and c2 (the multipliers) are positive.

Theoretical vs execution; same-complexity tie-breaks

Asymptotic analysis comes from theoretical analysis of the algorithm, not from the code side; it bridges the theoretical gap and the execution gap, letting you identify computational complexity even before execution of the code. If a wrong choice of g(n) is made, you will never correctly conclude the computational complexity. The notations are just nomenclature — the central idea is the order of complexity (n², n log n, log n, n³, n⁴); big O, big omega and big theta are the ones that appear, little o and little omega are for completion and will very rarely appear. When two algorithms share the same big-O complexity, other factors decide: merge sort and quicksort are both order n log n, but merge sort uses extra space during execution while quicksort does not (hence "quick"); then space complexity and the ignored lower-order terms come into the picture.

Formulas and maths

Worked examples

Questions asked in class

Transcript

One line per segment, [hh:mm:ss] timestamp first.

loading…