classnotes RTX 4070 Ti SUPER · faster-whisper · DeepSeek

5101 - Design & Analysis of Algo

← 5101 - Design & Analysis of Algo

DAA_27 Sep_Lab

Date 2026-09-27 Length 1h 50m Words 10,486 Segments 1,667
⤓ Download transcript (.txt with timestamps) ⤓ Plain transcript (.txt) ⤓ Transcript (.md)

Summary


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

title: "DAA 27 Sep Lab"

date: "2026-09-27 00:00"

duration: "1h 50m"

language: "en"

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

parts: 2

transcript_chars: 49803

generated: "2026-11-23T23:48:48+05:30"


DAA 27 Sep Lab

Overview

This class completed the divide-and-conquer sorting unit: it walked through merge sort's divide and merge steps with a full dry run on an 8-element array, then developed quick sort from the pivot/partition idea through the recursive calls and a code dry run. The session then moved to two new algorithms — maximum subarray sum (Kadane's algorithm, brute force vs. single pass) and binary search — and closed with course logistics (hidden test cases, a lab extension, feedback link). It sits after the introduction of recursion and divide-and-conquer and before the upcoming "cadence" algorithm and further binary search work.

Learning outcomes

Core concepts

Merge sort (recap)

Divide the array into two halves, recursively sort both halves (left side first, then right side), then merge using a merge function that takes only the left and right parts; leftover values are appended to the result. The base condition is: if the length of the array is <= 1, return the array — it exists because the function recursively calls itself and needs a stopping point. This is the reference divide-and-conquer sort against which quick sort is contrasted.

The merge function

Starts with i = 0, j = 0 and a result array; compares left[i] with right[j]; if left[i] < right[j] it appends the left value and increments i, otherwise it appends the right value and increments j. After the main loop, remaining (already sorted) elements are appended without further comparison. append adds an element to the last position of the array. This is the "combine" half of merge sort.

Python slicing

array[start:end] goes from start up to end; with no start/end given it goes from the first element to the last. A step value skips elements — e.g. on 0 1 1 2 3 with step 1 starting from 0, only 0 and 2 are picked (it skips one value each time). Slicing is how the merge sort code produces the left and right halves.

Quick sort

Also divide and conquer, but the major difference is that merge sort divides first and sorts while merging, whereas quick sort places a pivot in its correct position first, then recursively sorts the elements on its left and right. The pivot is "like a center position" — any element chosen as the pivot; it is placed into its correct (final sorted) position. Philosophy: choose the pivot, put everything smaller on the left side and everything bigger on the right side, then quick sort the left side and then the right side.

Partition and the pivot

After the first partition, the pivot is in its final sorted position; everything to its left is smaller and everything to its right is larger, but the two sides are not necessarily sorted yet. Boundary i represents the boundary of elements that are smaller than or equal to the pivot; initially there are no such elements, so i = -1. The partition explanation is marked as "very important."

Quick sort base condition and recursion

Quick sort checks if low > high (unlike merge sort, which checks length ≤ 1), because it checks from both sides; if the indices have crossed/swapped, it returns. low and high are indices only (not arrays) — the call is made with 0 and length of array - 1. After partitioning returns the pivot index, recursively sort the left side with (array, low, pivot index - 1) and the right side with (array, pivot index + 1, high). There are two separate functions: one is the partition, the other is quicksort. Pivot choice is flexible: it can be the first element or any element, not necessarily first or last.

Swapping in Python

Done directly as array[i], array[j] = array[j], array[i] — no third variable needed (unlike C/C++). Used throughout the partition step.

Maximum subarray sum (Kadane's algorithm)

Find the contiguous subarray with the maximum sum. Brute force maintains a result and uses two loops (one over the whole array, one over the internal array), comparing results; time complexity around 9 × 9 = 81 for 9 elements, which is "not cool." The single pass maintains a current sum (sum up to now) and a global/maximum sum, updating both in one pass to keep time and space complexity low.

Binary search

Searching by looking at the middle and eliminating half of the array each time, instead of checking every element (linear search). It only works for a sorted array. Uses three pointers: low, mid, high. Described as "the easier one."

Formulas and maths

Worked examples

Merge sort dry run on [10, 7, 8, 9, 1, 5, 3, 2] (8 elements; the transcript also refers to the array as 1, 2, 3, 6, 7, 8-style values — the concrete values used in the run are the ones below):

Quick sort example on [8, 3, 5, 4, 7, 6, 1, 2] with the last element 2 as pivot:

Quick sort code dry run on the same array (call quicksort(array, 0, 7)):

Quicksort — right-side recursion and partition dry run:

Kadane's dry run (array begins with −2, 1, −3, 4, ...):

Binary search example:

Questions asked in class

Transcript

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

loading…