5101 - Design & Analysis of Algo
← 5101 - Design & Analysis of Algo
session: "5101-design-analysis-of-algo/2026-09-12 0000 DAA 12 Sep"
title: "DAA 12 Sep"
date: "2026-09-12 00:00"
duration: "1h 25m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 2
transcript_chars: 49126
generated: "2026-11-23T23:39:04+05:30"
This class recapped the computational complexity of insertion sort (order of n square) and loop invariance as a tool for checking algorithm correctness, then revisited asymptotic notations — big O, big omega, theta, little o and little omega — along with their properties (reflexivity, transitivity, symmetry, addition, multiplication) and why asymptotic analysis is useful. The second half introduced the divide and conquer paradigm and began merge sort as its first algorithm, covering its three steps (divide, conquer/merge), its properties (stable, predictive performance, adaptable, higher space complexity, not in-place), and a full worked illustration on an 8-element array. Merge sort's complexity intuition (log n for division, order of n for merging, giving n log n) was established, with the formal recurrence relation and asymptotic analysis deferred to the next class.
Three conditions: initialization (some condition holds before the loop starts), maintenance (it is maintained during execution of the loop), and termination (after the loop terminates we get the desired result, unchanged by the loop). It is used for checking algorithm correctness. In insertion sort: at initialization we have just picked up the first number, and a single number is already sorted, so the condition is true; during the loop, at step 3, 5, or i, all elements up to that position are sorted after each iteration; at the end we get the sorted array. In merge sort, the loop invariance stated in class is that every time, the small array obtained is sorted.
Big O is primarily confined to the upper bound — the half portion of theta notation covering c1 g(n) ≤ f(n) ≤ c2 g(n) (the upper part); i.e., the maximum time the algorithm will take. Big omega is the other half portion; it identifies the minimum time taken by the algorithm (at least what time it will take). Theta bounds on both ends (between maximum and minimum). Little o / little omega are notations where the ratio of f(n) by g(n) is not equivalent to 1 when n tends to infinity; these are not asymptotic (tight) bounds. If a higher order of g(n) is considered, it is little o, where f(n) ≤ c·g(n). Little omega is a variant of big omega imposing a stricter bound; used when f(n) is greater than g(n) (higher f(n), lower g(n)). For all notations we look at the dominating term.
The highest-degree term with positive coefficient; it plays the pivotal role and leads to the computational complexity when n tends to infinity. To identify which notation an equation represents, simply pick the highest order term and check if its coefficient is positive; that term dominates when n is large. We are not getting exact time, only the order as n increases (quadratic, cubic, n log n, log n). Big omega (minimum time), big O (maximum time) and theta (how the algorithm propagates) all depend on the high order term.
Helps analyze time complexity, understand space complexity, compare algorithms (most important), and identify the dominating term that plays a critical role in determining computational complexity. It provides platform independence, shows an abstract version of the algorithm, helps select a good algorithm for the problem, and makes scalability predictable without running the code explicitly. The notations are primarily for time complexity in asymptotic analysis, but they hold in terms of space complexity as well — while estimating f(n) we can also estimate the space requirement.
An algorithmic paradigm (alongside brute force) where a large problem is divided into smaller problems, the division continues until a specific condition is reached, then the subproblems are conquered (solved), and finally the solutions are combined. Combine is sometimes also called merge. It is also a military strategy ("divide and conquer" — divide the kingdom so an outside power can rule). Merge sort is the first algorithm seen under it.
The first algorithm covered that follows divide and conquer. It efficiently sorts an array or list by recursively dividing it into smaller subproblems. Its worst, average and best cases all lead to order of n log n. The three steps: divide, recursively sort (conquer), combine (merge). Division strategies are n/2, floor(n/2), ceiling(n/2); the famous one is int(n/2) because it is easy to implement, and whichever is chosen must be consistent for all rounds of that algorithm. Division imposes no comparison cost (just n/2, n/2, n/2 ...); the conquer step does the comparisons. The algorithm first completes the left subpart, then goes to the right subpart (sequential, not parallel). Implementation sketch (Python-style): if array length is less than one, return the array (no sorting possible); otherwise middle = length of array / 2; recursively call merge sort on the left half and on the right half; return left half and right half via the merge operation, which stores into two subarrays, compares element by element, and declares the result.
The relative order of equal elements is maintained in the sorted output. Example: an array containing two 1s (first appearance and second appearance) — after sorting, the first 1 still appears before the second 1; same for two 4s. Insertion sort as well as merge sort are stable sorting algorithms. Practical relevance: processes with priorities are executed first; if two processes of similar nature try to access the machine, first come first serve is followed — if both have the same priority, the element appearing first is preferred.
In-place sorting: the sorted output is stored in the same array from which execution started; no extra space is required for storing the answer. Insertion sort is in-place (array A is used for comparison and the result is also stored in A). Merge sort starts with array A but stores the result in array S, so it is not in-place. During merging, two subarrays s1 and s2 are used and the result is stored in s; for each sub-case s is temporary, but at the end the final s is a different array from A — hence the additional space requirement (temporary storage as well as storage for the final result). External sorting: when RAM has limited space and cannot accommodate more elements, an external device / external storage can be used to preserve the result. Merge sort is adaptable — well suited for linked lists and external sorting; it requires extra space to store the sorted elements, but that space may reside outside the RAM. Predictive performance: the computational complexity can easily be predicted for any case — theta, big omega or big O are all n log n, whatever the condition.
c1 g(n) ≤ f(n) ≤ c2 g(n). Symbols: c1, c2 are constants and g(n) is the bounding function. Used to express a bound on both ends (between maximum and minimum).f(n) ≤ c·g(n) (with higher order g(n)). Symbols: c is a constant, g(n) a higher-order function. Used when g(n) is of higher order than f(n) — not a tight/asymptotic bound.Insertion sort loop invariance walkthrough: single element sorted at initialization; sorted prefix at each step i; sorted array at termination. Insertion sort complexity analysis reached order of n square (recap).
Identifying notations:
Reflexivity example: f(n) = 2n² + 6n + 9, g(n) = 2n² + 6n + 9 — reflexivity holds.
Transitivity example: f(n) = 6n² + 9n − 27, g(n) = 3n², h(n) = n² → f(n) = big O(3n²), 3n² = big O(n²), hence f(n) = big O(n²).
Growth comparison: f(n) = 3n² + 2n log n vs g(n) (without a quadratic term) → f(n) grows faster because it has a quadratic term; 2n log n grows slower than 5n log n.
Sequential vs nested loops: sequential loops: 3n² + 2n + 9 (one loop, another loop) — addition property; another aggregation example 0.5n² + 7n + 9. Nested loops: n × n (multiplication property).
Merge sort vs quick sort: both n log n; merge sort uses external storage, quick sort does not; quick sort is faster in average and best case, merge sort is better in worst case.
Space examples: insertion sort order of n (one array), merge sort order of 2n (two arrays); dynamic programming stores previous values (temporary storage is more).
Division of an 8-element array (using n/2 policy): 85, 24, 63, 45, 17, 31, 96, 50.
Merging (conquer/combine):
Stable sort example: unsorted array 1, 7, 3, 4, 9, 11, 10, 6, 5 with a second 1 (and a second 4) — after sorting, the first occurrence stays before the second occurrence.
Q (conditional/complex operations inside a loop): If a loop runs n times and the conditional part has a complex condition that also takes time, why is that factor not considered?
A: If some operation runs n times inside a for loop, it will impact; complexity follows the multiplicative property (n into n or something). If it is a simple print or assignment operation it can be ignored, otherwise it will impose cost.
Q (mailing questions): Can students mail questions from recorded videos?
A: Yes, definitely; the instructor will try to resolve them.
Q (reflexivity): Request to repeat the reflexivity property.
A: With f(n) = 2n² + 6n + 9 and g(n) the same, since big O has an equality condition (f(n) equivalent to c·g(n) for some c), f(n) = big O(f(n)) and g(n) = big O(g(n)); the interchange is possible. Reflexivity means a function is asymptotically equivalent to itself; f(n) belongs to a set of theta(g(n)), and one value is f(n) itself.
Q (serial 3 slide, 3n² + 2n log n vs g(n)): Why is 2n log n taken as higher order degree here?
A: f(n) = 3n² + 2n log n grows faster than g(n) because it has a quadratic term while g(n) has none; 2n log n is slower than 5n log n.
Q (aim of analysis): Is the ultimate aim of all this analysis to optimize the algorithm?
A: Yes — to optimize and compare which algorithm is best (n log n over n square), reduce time and space complexity, provide platform independence, show an abstract version of the algorithm, help select a good algorithm, and predict scalability without running the code.
Q (practical tools): Are there tools where an algorithm is uploaded and it gives the complexity and where it can be optimized?
A: Platforms like HackerRank, Codeforces, etc. automatically estimate time complexity, but asymptotic analysis is more or less a theoretical analysis rather than a practical one.
Q (identifying big O from an equation): How do we identify which notation an equation represents?
A: Simply pick the highest order term and check if its coefficient is positive; that term dominates when n is large, so we declare e.g. big O of n square — the maximum time is of that order. We are not getting exact time, only the order as n increases (quadratic, cubic, n log n, log n). For all notations we look at the dominating term: big omega (minimum time), big O (
One line per segment, [hh:mm:ss] timestamp first.
loading…