CS252 Algorithms Wednesday, 3 April 2024 + Questions - Hash tables? Off limits all term. + Slack - Threads & notifications - Recommended: skim everything, don't skip the threads - Should I use @channel? + O(m + n) - Searching tip: O, Ω, ϴ are called "Landau notation" (or "Bachmann–Landau") - Big-oh with multiple variables f(x,y) = O(g(x,y)) if ∃ C > 0, N > 0 st x >= N and y >= N ==> f(x,y) <= Cg(x,y) - What does that mean for an arguably two-variable situation like Problem 1? + Data structures; let's look at - Arrays - Linked lists - Singly-linked - Doubly-linked - With and without tail pointer - Stacks - Implemented with an array (variables? push and pop operations?) - Implemented with a linked list (variables? single/double/tail? push and pop operations?) - Queues - Implemented with an array (variables? add and remove operations?) - Implemented with a linked list (variables? single/double/tail? add and remove operations?) + Gale-Shapely correctness proof, super-short summary - Termination - Perfect match (n pairs, no repeated m or w) - Stable match + Gale-Shapely correctness proof, longer summary - (p7, 1.1) After getting one proposal, a woman remains engaged - (p7, 1.3) GS terminates after at most n^2 iterations - (p8, 1.4) If man m is free, then there is a woman w that has not been proposed to by m - (p8, 1.5) At the end, the set S is a perfect matching - (p8, 1.6) At the end, the set S is a stable matching + Try a variant - what if there are more women than men, and men are still the proposers + Other stuff of interest - regardless of the order of the men selected in the loop, you get the same matching (whoa!) - once you understand the core theorem, there are tons of variants - allow preference ties ("indifference") - allow different sized sets - allow a single "job" to hire multiple "workers" (CS match) - ... - Reading proofs is not like other reading - Correctness requires that an algorithm terminates - Small examples (plus tinkering) help you get the feel of an algorithm ===== - Perfect match S is always a matching terminates w/ free man? Nope. - Stable Contradiction: Suppose \exists (m,w), (m',w') \in S where m likes w' better than w and w' likes m better than m' Then m proposed to w' earlier than he proposed to w. What happened then? case 1: m proposed to w' before m' did; w wouldn't have switched for m', so this couldn't be it case 2: m proposed to w' after m' did; w would have switched, so this couldn't be it Contradiction.