algo home
Resources for Algorithms
This page does not change much over time. It contains course notes and videos, as well as other useful information, organized by topic.
Course Topics (not necessarily in order of schedule)
- Things to review before starting this class
- big-O notation
- Recurrences
- Sorting
- Hashing
- Deterministic Selection (includes separate notes on partitioning)
- Indicator Random Variables
- Quicksort and RandSelect
- Binary search trees
- Augmenting data structures
- Amortized Analysis
- Dynamic programming
- Graphs: intro, BFS, DFS, topological sort, SCC
- Minimum spanning trees
- Single-source shortest paths
- P vs NP
Informal summary PDF
This PDF contains some brief informal descriptions of the course material. It's useful if you're looking for a quick summary, but it only complements the class notes, it does not replace them. If you spot any errors or particularly unclear descriptions, please let me know.
A note about videos
For most topics, live lectures were recorded in the Fall 2016 and Spring 2017 semesters at Tufts University. A couple were done in Spring 2018 at NYU. Because of some minor audio issues in some of the lectures, and because I have refreshed the course notes, I have started creating new videos. At first these will be voice-over presentations. Eventually they will be replaced with new recordings of live lectures. Until then, the old videos will remain available.
If you find a particular clip to be unclear, please let me know.
- Things to review before starting this class
- Discrete math
- Data structures
- Arrays, linked lists, stacks, queues, heaps, binary search trees. We will quickly recap the last two.
- You should understand that you can't access an arbitrary item in a linked list in constant time, or run binary search.
- You should understand that you can't insert an element into the middle of an array in constant time.
- Basic probability
You should know what expected value is. See here.
- big-O notation (aka Theta notation)
- Prerequisite knowledge: it helps to be familiar with common functions (see 1.1 above)
- Class notes:
- Video
- Book: chapter 2, p.43-52. (For insertion sort, p.16-29)
- Recurrences
- The recursion tree. Using induction.
- The Master method
- New class notes:
full slideshow and
condensed
- New video:
- Old class notes:
full slideshow and
condensed
- Old video:
My 2017 lecture. (47min). Note that it is titled "part 1", but in fact it is self-contained. "Part 2" is just Strassen's algorithm, in section 3.3.d.
- Book: chapter 4, p.93-96, although more intuition can be gained by reading up to p.99.
- FYI: the Akra-Bazzi method generalizes the master method. This is beyond the scope of this course.
- Examples of using recurrences; recursive algorithms. (Just browse, this is not exam material)
- Divide and conquer, and binary search.
- Computing the power of a number
- Computing Fibonacci numbers
- Matrix multiplication (Strassen's method)
- VLSI embedding
- Sorting
- Insertion sort (used as motivation for big-O; see section 2)
- Merge sort (used as motivation for studying recurrences; see section 3.1)
- Heap sort
- Decision trees. Sorting lower bound.
- Counting sort and radix sort
- Other
- Quicksort is covered in section 8.
- Hashing (basics)
- Recap of competing data structures, and introduction
- New class notes:
- New video:
- Old class notes and video: contained in next section.
- Book: chapter 11, p.253-255
- Chaining
- Open addressing, linear and quadrating probing, double hashing, analysis with uniform hashing assumption.
- Advanced further reading, not part of this course: Universal hashing, Perfect hashing, Cuckoo hashing (and more about the
cuckoo mafia)
- Deterministic Selection (aka order statistics; median-finding)
- Partitioning
- General approaches towards getting linear time algorithms (including "prune and search")
- Prerequisite knowledge: Recurrences (by induction; section 3.1)
- Algorithm
- Sections 6.1 and 6.2 are not critical for this, but they might help. You will need to understand section 3.1 though (recurrences by induction).
- Book: Chapter 9, p.220-222.
- A
quote by
Bernard Chazelle.
- Indicator Random Variables
- New class notes:
full slideshow
and condensed
- New video: Slideshow with audio
- Old class notes:
full slideshow
and condensed
- Old video:
- Book: Chapter 5
- Examples
- The hat check problem.
- FYI -
Link 1 and
link 2 calculate the probability
of an outcome for this problem, without IRVs.
- The hiring problem.
- Link.
Note that the second problem in this link, involving birthdays, is mentioned below.
- Harmonic series (related to the hiring problem).
- Finding local maxima in permutations.
- Jump to the 30:00 mark in this youtube video,
which is part of Harvard's
Stat 110 course. This part of the lecture lasts 9 minutes.
After that is an explanation of the St. Petersburg paradox which is fun to think about.
Here's the wiki on that.
- Counting inversions in permutations. (involves IRVs with 2 subscripts)
-
Look at problem 2 in this
homework set
from a course at WVU. This follows the hat check problem. Problem 3 is not related to IRVs, but is interesting.
- A birthday problem. (involves IRVs with 2 subscripts)
- The 2nd example in this
link
is a variant of our good old birthday problem. I discuss this and one more variant
here.
- A problem with balls and bins.
- See the second example in this link.
Evaluation of the expected value of each IRV is a bit more complicated in this example than in previous ones.
Note that the first example in this link is equivalent to the hat check problem. It deals with fixed points in permutations.
In a permutation of the integers 1...n, a fixed point occurs when integer k is placed at position k.
- Quicksort and RandSelect
- Quicksort
- Introduction and short derivation of expected runtime
- Analysis 1: expected runtime, with more detailed analysis
- Recommendation: Look at the similar analysis for RandSelect first.
- Analysis 2: expected runtime via expected number of comparisons
- RandSelect (Randomized Selection)
- Binary search trees
- Basics
- Building a BST randomly, average depth, and relation to Quicksort.
- Prerequisite knowledge: Expected value.
- New class notes:
full slideshow1 (about time),
full slideshow2 (about height),
and all notes condensed.
- New video:
1: Intro and expected time.
2: Expected height. (Slideshow with audio)
- Old class notes:
full slideshow
and condensed.
- Old video:
- My 2019 lecture
(28 minutes)
- My 2016 lecture. (24min.) [Note: since making this video I have added material to the end of the corresponding course notes. The quick analysis of expected height is not in this video.]
- If you're interested in seeing the more complicated proof of why the expected height of a random BST is only 3logn, I can share course notes and a 40 minute video, just ask. There is also a version in CLRS chapter 12.4, p.299-302, but it uses certain results without proving them.
- Red-black trees (an example of dynamic balanced BST)
- Augmenting data structures
- Prerequisite knowledge: binary search trees (section 9)
- Intro, dynamic rank finding and dynamic selection
- Range counting (almost the same as dynamic rank queries)
- Interval trees
- Amortized analysis
- Class notes:
-
Video:
- Intro
- Multipop
- Binary counter
- Array doubling.
- Invariants in the accounting method:
slideshow with audio
- Potential functions without ideal conditions:
slideshow with audio
- FYI: BB-alpha trees.
- Book: Chapter 17.
- Blooper from a malfunctioning clicker during a Fall'16 review session.
- Dynamic programming
- Counting paths
- Longest common subsequence
- Longest increasing subsequence
- Rod cutting
- Graphs: intro, BFS, DFS, topological sort, SCC
- Representation and types of graphs (and a little bit about planarity)
- Breadth-first search (BFS) and depth-first search (DFS)
- Class notes:
full slideshow
and condensed
- Video: My 2016 lecture:
- Book: Chapter 22, p.594-610.
(Note, the book analyzes BFS and DFS more formally than I care for)
- Visualizations for
BFS
and
DFS by David Galles.
- xkcd 761
- Topological sort
- Strongly connected components
- Minimum spanning trees
- Prerequisite knowledge: graph basics, familiarity with priority queues (e.g. heaps).
- Intro and properties
- Kruskal's algorithm
- Prim's algorithm
- Prerequisite knowledge: Familiarity with heaps as priority queues.
- Single source shortest paths
- Prerequisite knowledge: graph basics.
- General properties, relaxing edges.
- Dijkstra's algorithm
- Prerequisite knowledge: Familiarity with heaps as priority queues.
- New class notes, describing the algorithm without assuming knowledge of Prim:
full slideshow
and
condensed.
- New video (Slideshow with audio)
- Old class notes, assuming knowledge of Prim's MST algorithm:
full slideshow
and
condensed.
- Old video:
My 2016 lecture. (7 minutes) [The slide with the proof has been updated since this video was made. Specifically, the initial weights used in the video are inconsistent with the inductive hypothesis. The point is still made though.]
- Book: Chapter 24, p.658-662.
- Visualization by David Galles.
- JavaScript demo by Kenji Ikeda.
- Bellman-Ford algorithm
- Algorithm for DAGs
- Note: the proof of correctness relies on the main lemma that comes before Bellman-Ford.
- P vs NP
- Intro
- Class notes:
full slideshow
and
condensed
- Video: My 2016 lecture until 28:00, then continues with reductions.
- Book: Chapter 34, p.1048-1053, and 1061-1069.
However, I introduce the topic more informally, for instance, without mentioning "languages".
- Examples of reductions
- Class notes:
full slideshow
and
condensed
- Video: My 2016 lecture part 1 (starting from 28:00, i.e., continuing from above), then
part 2
- Book: Chapter 34, from p.1070 and on.
This goes into much more detail than I will. Just browse through accordingly.
- Other
- Use your new-found knowledge to torment your friends.
- Here are two papers about well-known video games that can be generalized to be really hard.
__1__
__2__
- A brief, mostly non-mathematical, introductory
video about P vs NP, shown to me by a former CS-2413 student.