CS 325-001, Analysis of Algorithms, Fall 2019

Coordinates T/Th, 10-11:20am, LINC 210 [Registrar] [Canvas] [Slack]
Instructor Liang Huang (huanlian@)
TAs Sizhen Li (lisiz@), Liang Zhang (zhanglia@), and Renjie Zheng (zhengr@)
Office Hours Instructor: T/Th, 11:30am-12pm (KEC 2069)
TAs: M: 3-4pm and 5-6pm; W: 4-6pm; F: 4-6pm (KEC Atrium).
Extra office hours available before exams.
Textbooks [CLRS] Introduction to Algorithms, 3rd or 2nd edi. (default reference).
[KT] Kleinberg and Tardos, Algorithm Design (DP chapter online, all slides online)
[DPV] Dasgupta, Papadimitriou, and Vazirani (DPV). Algorithms (full text online via berkeley)
[E] Jeff Erickson. Algorithms, Etc. (full text online)
How to Think Like a Computer Scientist: Learning Python (full text online)
Grading (tentative) Midterm: 20%, Final: 25%, Quizzes: 8+8=16%;
Weekly homework: 3x8%+6%=30%, Class Participation: 2%.
For each HW, any complete submission automatically gets 2%.
The other 1% is based on blackbox testing of the specified coding problem.
Remaining 7%: everybody gets full marks.
Coding must be done in Python 3.
no late submission is accepted.

Class participation: we reward the following:
(a) correctly answering other students' questions on Slack;
(b) participating in surveys on Canvas (for me to get feedback);
(c) finding mistakes in any teaching material.

Grading Curve: A/A-: [90,100]; B+/B/B-: [60,90); C: [50,60); F: [0,50).

Prerequisites Students are assumed to be familiar with Data Structures (CS 261) and fluent in at least one mainstream language (C/C++, Java, Python). We'll start with a brief review of Data Structures integrated with a Python tutorial.
Other Policies Canvas is for announcements (you'll receive an email for each announcement I made on Canvas) and checking grades, and Slack is for discussions.

For technical questions, come to office hours. Otherwise you can raise a question on Slack.
For questions about grading or grades, come to the office hours. Do not email us unless you have a personal issue.


Objectives

The purpose of this course is six-fold:

Topics Covered

  1. Python Tutorial, Review of Basic Data Structures, Sorting and Selection
    (divide-n-conquer, quicksort/quickselect, mergesort, BSTs, memoization, heaps and heapsort, priority queue, hashing, hashed heap, etc.)
  2. Basic Complexity Analysis (Master equation, recursion tree method, amortization, etc.)
  3. Dynamic Programming (DP)
  4. Graph Algorithms: BFS/DFS, topological sort, Dijkstra, Viterbi, Prim, Kruskal, TSP
  5. NP-Completeness

Detailed Schedule and Materials

WeekTopicsHomeworkQuiz/Exam
1 (Thu) Admin
Python Tutorial (first 5 pages)
quicksort, BST, quickselect
HW1
(qselect, qsort->bst)
2 (Tue) brief discussions of HW1
tail recursion; non-recursive qselect
divide-n-conquer: quicksort vs. mergesort
merging two sorted lists via two-pointers
stable sort; motivations: sorting with multiple keys
stable: mergesort, insertion sort, non-randomized quicksort
not stable: randomized quicksort, selection sort (but can be made stable)
insertion/selection sort are "slow": O(n^2)
insertion sort with binary search: n x (O(logn) + O(n)) = O(n^2) still

(Thu) divide-n-conquer: number of inversions
longest path in binary tree
quiz1

HW2
(msort, inv, longest)
Thu: Quiz 1
(covers HW1)
3 (Tue) hand out graded quiz1
insertion sort can be made O(nlogn) by balanced BST
discussions of HW2:
qsort with randomized pivot made stable by 3-way partition
generic way to stablize sort: decorate-sort-undecorate
mergesort implementation: mergesorted(a[1:], b) is O(n^2)
k numbers closest to input query, sorted
(Thu) k numbers closest to input query, unsorted; bisect.bisect
x+y=query: O(n^2)->O(nlogn)
x+y=z: O(n^3)->O(n^2 logn) -> O(n^2)
x+y=z: hashing (python set): O(n^2)
Priority Queue (emergency room)
slow implementations: sorted list, reversely sorted list, sorted linkedlist
fast implementation: binary heap; bubble-up/bubble-down
HW3
(k-closest, two pointers)
4 (Tue) brief discussions of HW3
heapify is O(n)
Python heapq tutorial
heapq bubble-down follows Knuth (vol.3) and different from textbooks
k-way mergesort
(Thu) data stream
quiz2 and discussions
HW4
(priority queues; baby Dijkstra)
Thu: Quiz 2
(covers HWs1-3/quiz1)
5 (Tue) handout Quiz2
discussions of HW4
heapify is O(n)
(Thu) DP 101: Fibonacci, memoization, bitstrings, max. indep. set [slides]
HW5
(DP I: memoized Fibonacci, # of BSTs, # of bistrings)
6 (Tue) Knapsack: unbounded and 0-1
KT slides (pp. 30-37)
(Thu) Knapsack: bounded
Discussions for HW5
Midterm Review problems [solutions]
HW6
(DP II: knapsack, unbounded and bounded)
7 (Tue) Discussions of HW6
Q/A session
(Thu) Midterm
Thu: Midterm
8 (Tue) Discussions of Midterm solutions
graphs: intro
topological sort (BFS-style)
handout graded midterms
(Thu) in-class coding session: topol sort: stack and queue
Viterbi
Dijkstra intro
HW8
(Topol, Viterbi)
9 (Tue) Dijkstra: decrease-key; hashed heap (heapdict)
KT slides demo
HW8 solutions
(Thu) CKY: RNA structure
KT slides
HW9
(Dijkstra; redo one midterm question)
10 (Tue) counting and k-best RNA
(Thu) Thanksgiving
HW10 (RNA structure)
11 (Tue) in-class coding session: k-best RNA
(Thu) Review problems updated solutions
optional hw11 (edit-distance)
12 FINAL Fri 12/13 9:30am-11:20am
same room, closed book, closed notes


Resources

The last two are different from the rest in the sense that they ask you to submit your output to given testcases rather than programs (so that you can code in any language, and their online judge system is as easy as a diff). There are many other online judge systems that do not support Python (traditionally ACM/ICPC uses C/C++/Java/Pascal), such as the classical uva (Universidad de Valladolid), poj (Peking University), tju, hit, hust, bjtu, etc. (almost all major Chinese universities run their own online judge systems); you can hone your C/C++/Java skills there if you have extra time. Thanks to my former intern Zhuoran Yu for compiling this list.

To prepare for coding interviews, you have to practice on some of the above (say, solving at least 20 problems on codeforces, with at least two from each topic). To prepare for ACM/ICPC, you have to practice a lot (solving at least 100 problems on zoj/poj).


Liang Huang