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.
If you want a supplemental video source, check out the
MIT open courseware video lectures for Intro to Algorithms, starring Charles Leiserson and Erik Demaine (from 2005).
This is entirely optional. They cover a few things that we don't, and vice versa.
Here is the
link
(which seems to have subtitles too).
You can also view or download the free videos (without subtitles) at the iTunes store by searching for "Introduction to Algorithms", or
here.
- Things to review before starting this class
- Discrete math
- Data structures
- Arrays, linked lists, stacks, queues. Also, heaps and binary search trees, but they are introduced on this page anyway.
- 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. [You can also see the intro of the IRV section below]
- 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.
- MIT videos: Lecture 2 from 48:35 to end.
- 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.
- MIT videos: Lecture 3 up to 13:00
- Book: chapter 4, p.65-67
- Computing the power of a number
- MIT videos: Lecture 3 from 13:00 up to 17:40
- Computing Fibonacci numbers
- Matrix multiplication (Strassen's method)
- My 2017 lecture. (13min.)
- MIT videos: Lecture 3 from 33:45 to 54:40
- Book: chapter 4, p.75-82.
- VLSI embedding
- MIT videos: Lecture 3 from 55:00 to end.
- Sorting
- Insertion sort (used as motivation for big-O; see section 2)
- MIT videos: Lecture 1, 17:20 to 1:03:20.
- Book: chapter 2, p.16-29
- Merge sort (used as motivation for studying recurrences; see section 3.1)
- MIT videos: Lecture 1, 1:03:20 to end.
- Book: chapter 2, p.30-38
- Heap sort
- Decision trees. Sorting lower bound.
- Counting sort and radix sort
- New class notes:
full slideshow and
condensed
- Old video on Counting sort: (2017 lecture)
First 17 minutes only
- New video on Radix sort: Slideshow with audio
- MIT videos: Lecture 5, from 31:20 up to 1:04:00.
After that the video has a more detailed analysis of radix sort.
It is also in the book, but you are not required to cover this.
- Book: chapter 8, p.194-199.
- Visualizations for
Counting sort and
Radix sort by David Galles.
- 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
- Class notes:
full slideshow
and condensed
- 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
- 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.]
- MIT videos: Lecture 9, up to 22:30.
- 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
(There's a harmless parenthesis typo on slide 14; it has been corrected in the course notes)
- FYI: BB-alpha trees.
- MIT videos: Lecture 13 (for array doubling). Note that a different potential is used, compared to my class notes.
- 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)
- Class notes:
full slideshow
and condensed
- Video
- My 2016 lecture:
- MIT videos: Lecture 16, up to 23:20.
- Book: Chapter 22, p.589-592.
- 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
- Class notes:
full slideshow
and condensed
- Video:
- My 2017 lecture: Part 1, and
Part 2 (until 20:22, then Kruskal's algo begins)
- MIT videos: Lecture 16, from 23:20 up to 1:00:30.
- Book: Chapter 23, p.624-629.
- 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 (7min; start at 2:00)
[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.]
- MIT videos: Lecture 17, from 26:20 to 1:19:40. (the proof of correctness is far longer than what I require)
- Book: Chapter 24, p.658-662.
- Visualization by David Galles.
- JavaScript demo by Kenji Ikeda.
- Bellman-Ford algorithm
- Class notes:
full slideshow
and
condensed
- Video:
My 2016 lecture (main lemma starts at 15:04, algorithm starts at 21:20; total 22 minutes)
- MIT videos: Lecture 18, up to 36:00. (more rigorous than what we will do).
- Book: Chapter 24, p.651-654.
- xkcd 69
- 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.