classnotes RTX 4070 Ti SUPER · faster-whisper · DeepSeek

5101 - Design & Analysis of Algo

← 5101 - Design & Analysis of Algo

DAA_13 Sep

Date 2026-09-13 Length 1h 23m Words 9,030 Segments 494
⤓ Download transcript (.txt with timestamps) ⤓ Plain transcript (.txt) ⤓ Transcript (.md)

Summary


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

title: "DAA 13 Sep"

date: "2026-09-13 00:00"

duration: "1h 22m"

language: "en"

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

parts: 2

transcript_chars: 44944

generated: "2026-11-23T23:40:36+05:30"


DAA 13 Sep

Overview

This class completes the asymptotic-notation recap (big O, big Omega, big Theta, little o, little omega, plus reflexivity, transitivity, symmetry, and additive/multiplicative properties) and then introduces the divide-and-conquer paradigm through merge sort: the divide/conquer/combine stages, the merge operation, and full worked traces on 8-element and 7-element arrays. It then derives the merge sort recurrence T(n) = 2·T(n/2) + order of n and contrasts it with binary search on a sorted array, whose recurrence is T(n) = T(n/2) + order of one. The class also reviews in-place vs. stable sorting, duplicates in merge sort, and the space–time trade-off, and closes with course logistics (assignment 1, mid-semester, end-semester). It sits at the transition from complexity analysis into algorithm design, with recurrence-solving methods (master's method, recursion tree, substitution) and quick sort explicitly postponed.

Learning outcomes

Core concepts

Asymptotic notation recap

Big Omega, big Theta, and big O are the three main notations; little o and little omega are the two others. Little o/little omega are used when the ratio of F(n) and G(n) is not equivalent — i.e., when the chosen value is not equivalent to the value specifying the property of an algorithm. When f(n) is less than g(n), we confine to little o; when f(n) is greater than g(n), we say it is little omega. This matters because it is the vocabulary for every complexity claim in the course.

Highest-degree-term rule

To identify big O, big Omega, or big Theta for any function, always identify the highest-degree term with a positive coefficient; then you can directly claim the complexity (e.g., order of n cube, order of n square) without calculating c1, c2, c, n0. This is the fast path used throughout the course.

Properties of asymptotic notation

These properties are what let you collapse a messy algorithm analysis into a single term.

What asymptotic notation provides

Capability to identify computational complexity of two algorithms / help in algorithmic selection; simplification and abstraction; platform independence; prediction of scalability and behavior as input size increases. This is the "why" behind the whole notation unit.

Divide and conquer

If the problem size is very large, divide the problem into subproblems and sub-subproblems until very small size, then conquer (solve the subproblems) and combine (merge the solutions). Three stages: divide (partition the large problem into smaller and smaller pieces), conquer (use a divide and conquer algorithm to solve the subproblem associated with the subset), combine (take the solutions of the subproblems and do a merger). This is the design paradigm that merge sort and binary search instantiate.

Merge sort

A famous divide and conquer problem. The division strategy divides until a single-element level is reached; then recursively sort (conquer/combine) and perform the combination (merge) operation. Steps: recursively divide the array into one-element composition; merge two elements and sort the subset; repeat until the solution is reached. Division is easy; the merge is the important and critical part.

Merge operation

Two already-sorted subsequences are merged: compare the first element of one with the first element of the other; whichever is smaller is pushed into the final/resultant array S and eliminated from its subsequence; two pointers (i and j) move toward the end comparing one-by-one. When one subarray is exhausted, the remaining elements of the other are extended into the result without comparison (they are already sorted). This is the critical operation that determines the order-of-n combine cost.

Recurrence relation for merge sort

A representation of how an algorithm behaves: dividing n into 2 subproblems of n/2 and taking order of n for combining gives T(n) = 2·T(n/2) + order of n. Dividing takes order of one time because nothing is compared — we are just calculating n/2, n/2, n/2 and then dividing. The recursive calls occur until the sublist contains one element; this takes log of n. The merge takes order of n because we compare n/2 elements with n/2 elements, so the maximum number of comparisons could be n. Directly determining that it follows log of n is very difficult, so the recurrence is solved by master theorem (or recursion tree / guessing / substitution) to get n log n.

Binary search

Given a sorted array (ascending order) and a key value, identify the middle, compare with the key, and determine the direction — if the middle element is greater than the key, search left; if the middle element is less than the key, search right. Half of the array remains unusable once the actual direction of movement is known; each step reduces the search space, which is the beauty of the algorithm. Indexing can start at 1 or 0; for the middle you can take n/2 ceiling, n/2 floor, or n/2 int — totally up to you.

In-place vs. stable; duplicates; space–time trade-off

Insertion sort is in-place; merge sort is not in-place — "not in place means that the result will be stored into another array." Both are stable: the order of elements in the resultant array remains the same. With duplicates, the algorithm goes as it is and you will get the result; when comparing, "20 less than 20" fails, so that concept can be applied. On space: preference is always given to time; if there is a space constraint, follow "plan B," otherwise stay confined to the time complexity.

Formulas and maths

Worked examples

Merge sort on 8 elements: 85, 24, 63, 45, 17, 31, 96, 50

Merge sort on 7 elements: 38, 27, 43, 3, 9, 82, 10

Merge procedure example (instructor's illustration)

Extend illustration: If S1 has 0 entries and S2 still has elements (e.g., 74, 75, 73) while S has 1, 7, 9 already sorted, the remaining subarray is directly cut down and added without comparison. This can be the left or right subarray; the remaining elements are already sorted, so they are extended into the final result, and in that case the comparison will be lesser.

Merge sort structure (recurrence intuition): a problem of 4 divides into 2 and 2, and combining takes n; a problem of 8 gives 2 problems of 4, 4, and combining requires order of n time.

Binary search, first example: sorted array 1, 7, 9, 24, 29, 9, 31, 35, 45 (8 elements listed; the instructor notes you can do a 9th element). Key = 45. Apply n/2 → reach index 4, value 24. 45 > 24, so the left portion is irrelevant. Remaining 5 elements → 5/2 → take the second entry, 31. 31 compared with 45 → that portion is done. Remaining 3 elements → get 35; 35 compared with 45 → that portion is irrelevant. Come to 45 and 51; 45 compared with 45 → declare the result.

Binary search, second example: values 6, 13, 14, 25, 33, 43, 51, 53, 64, 72, 84, 93, 95, 96, 97; low index 0, high index 14. Key = 33. Using ceiling of n/2, reach index 7 (value 53). 33 vs 53 → it will never lie in that direction (array sorted), so consider only that portion. Then 0 to 6 → reach index with value 25; compare 33 with it → that portion is inefficient. Then get 43 → that portion is irrelevant. Finally 33 is both low and high index → get the result.

Searching 20: using ceiling of n/2, reach 100; 20 < 100 so the value may lie on the left, not the right. Then middle element is 20; compare 20 with 20 → declare the result. Found in just two comparisons: one with 100 and one with 20.

Questions asked in class

Q (Subhashish): If the biggest term has a negative coefficient, do we ignore it or not take it?

A: That is not solvable by asymptotic analysis; the assumption is that the highest order term should have a positive coefficient, then only asymptotic analysis can be applied.

Q: The last part of the merge sort explanation was not properly visible (screen may have frozen); can you explain the last portion after division?

A: Division and revision were clear; the instructor continued with the merge portion, noting the PPT is shared and the merge operation will be explicitly demonstrated.

Q: How is the middle calculated? For an odd number, 7 by 2 is 3 — is that what we use?

A: Yes; if middle is declared as an int variable you get 3. You are free to use floor, ceiling, or int, but once declared it should be specific and the same throughout the problem.

Q: What is result.extend doing?

A: append adds one element; extend adds extra entries/spaces to the list (specific to Python). Since the list is dynamic, after appending one element you extend it for further entries. More importantly, when one subarray has no elements left, the remaining elements of the other subarray are automatically appended without comparing (could be left or right portion), since they are already sorted; in that case the comparison will be lesser.

Q: Can you explain the procedure of merge with an example?

A: The instructor worked through the left = 17, 19, 23, 45 / right = 16, 24, 49, 95 example (see Worked examples).

Q: With one million/ten million items, merge sort requires additional space (twice the amount) to sort the array — is this the most efficient from industry standards, or is there something better?

A: Better than this is quick sort, the quickest algorithm; it will be covered in the next class. It does not use extra space and utilizes the same array for sorting — that is why it is called quick sort.

Ganesh (merge sort in-place/stable): Confusion over the earlier statement that merge sort is in-place and also stable.

A: Merge sort is not in-place; not in-place means the result is stored into another array. Insertion sort is in-place. Both are stable — the order of elements in the resultant array remains the same.

Ganesh (duplicates in merge sort): How to proceed when duplicate elements

Transcript

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

loading…