CS252 Algorithms Monday, 22 April 2024 + Exam - Possible 43; High 43; Median 35.8 (83%) - Notes on specific problems 1(d) - nesting doesn't guarantee n^2; what's justification enough? 1(a),2(a)(c),4(a) - know your definitions! 2(b) - read the whole question; "in the above example" 3(a) - clarification & assumptions 3(b) - contradiction is by far the cleanest & easiest way to prove this 4(c) - need to understand how the graph rep'n fits into the algorithm 5(b) - some odd stack stuff I didn't understand 6 - Examples! - General notes - learning and thinking about definitions - when is an example the right answer? - practicing with each algorithm - I'll send you an estimated course grade on or close to midterm break + Quick break + Coming next - A few more thoughts on Dijkstra's Algorithm - Minimum spanning trees - Prim's Algorithm - Kruskal's Algorithm + What do you do to learn a new algorithm? - Figure out what the problem is - What are the inputs? (and their properties) - What are the outputs? (and their properties) - Are there definitions I need to know? - Look at pseudocode - Run a small example (generic input) - Change some stuff and try again - Run another small example (weirder) - Go slow, make sure you're doing each step carefully and looking around to see the state of everything - Explain it to somebody - Reread the algorithm - Read multiple versions of it - Read correctness proof - Think about runtime - Read runtime analysis - Go back and redo some other steps + Digression - Automatic reallocation of arrays as they get bigger - python list [] - Java ArrayList - double-and-copy --> "amortized O(1)" append - "amortized" here means "you pay the total O(N) cost of a sequence of appends over time, but on average, it's O(1) per operation" - fixed-size-chunk-and-copy --> amortized O(N) append - last I checked, Java ArrayList does 1.4x-and-copy, which still gives amortized O(1) append - Point of doing this now - it's cool and I felt like it - we're starting to see mentions of amortized complexity in some reading ==== Jeff's pre-class version of the notes about "what do you do" above ==== - What's the problem we're solving? - Definitions! (sometimes I just memorize even before I quite get it) - Inputs - Outputs - Read the algorithm - Try some examples - Simple walkthrough on generic inputs - Weird inputs (like testing some code) - What if we did a step wrong? - ...just play around with it... - Go back and read the algorithm again - Check out somebody else's version (e.g., textbook vs. Wikipedia) - think about the differences - Feel good about the basic mechanisms? Now try reading the proof. - ...