你将学到什么
Graphs
Data Structure
Algorithms
Data Compression
课程概况
第二部分涵盖了图处理算法,包括最小生成树和最短路径算法;字符串处理算法,包括字符串排序、trie、子字符串查找、正则表达式、数据压缩。最后,课程将这些内容放到更大的语境中一览全貌并以此作结。
This course covers the essential information that every serious programmer needs to know about algorithms and data structures, with emphasis on applications and scientific performance analysis of Java implementations. Part I covers elementary data structures, sorting, and searching algorithms. Part II focuses on graph- and string-processing algorithms.
All the features of this course are available for free. It does not offer a certificate upon completion.
课程大纲
周1
完成时间为 10 分钟
Introduction
Welcome to Algorithms, Part II.
1 个视频 (总计 9 分钟), 2 个阅读材料
完成时间为 2 小时
Undirected Graphs
We define an undirected graph API and consider the adjacency-matrix and adjacency-lists representations. We introduce two classic algorithms for searching a graph—depth-first search and breadth-first search. We also consider the problem of computing connected components and conclude with related problems and applications.
6 个视频 (总计 98 分钟), 2 个阅读材料, 1 个测验
完成时间为 4 小时
Directed Graphs
In this lecture we study directed graphs. We begin with depth-first search and breadth-first search in digraphs and describe applications ranging from garbage collection to web crawling. Next, we introduce a depth-first search based algorithm for computing the topological order of an acyclic digraph. Finally, we implement the Kosaraju−Sharir algorithm for computing the strong components of a digraph.
5 个视频 (总计 68 分钟), 1 个阅读材料, 2 个测验
周2
完成时间为 2 小时
Minimum Spanning Trees
In this lecture we study the minimum spanning tree problem. We begin by considering a generic greedy algorithm for the problem. Next, we consider and implement two classic algorithm for the problem—Kruskal's algorithm and Prim's algorithm. We conclude with some applications and open problems.
6 个视频 (总计 85 分钟), 2 个阅读材料, 1 个测验
完成时间为 5 小时
Shortest Paths
In this lecture we study shortest-paths problems. We begin by analyzing some basic properties of shortest paths and a generic algorithm for the problem. We introduce and analyze Dijkstra's algorithm for shortest-paths problems with nonnegative weights. Next, we consider an even faster algorithm for DAGs, which works even if the weights are negative. We conclude with the Bellman−Ford−Moore algorithm for edge-weighted digraphs with no negative cycles. We also consider applications ranging from content-aware fill to arbitrage.
5 个视频 (总计 85 分钟), 1 个阅读材料, 2 个测验
周3
完成时间为 4 小时
Maximum Flow and Minimum Cut
In this lecture we introduce the maximum flow and minimum cut problems. We begin with the Ford−Fulkerson algorithm. To analyze its correctness, we establish the maxflow−mincut theorem. Next, we consider an efficient implementation of the Ford−Fulkerson algorithm, using the shortest augmenting path rule. Finally, we consider applications, including bipartite matching and baseball elimination.
6 个视频 (总计 72 分钟), 2 个阅读材料, 2 个测验
完成时间为 2 小时
Radix Sorts
In this lecture we consider specialized sorting algorithms for strings and related objects. We begin with a subroutine to sort integers in a small range. We then consider two classic radix sorting algorithms—LSD and MSD radix sorts. Next, we consider an especially efficient variant, which is a hybrid of MSD radix sort and quicksort known as 3-way radix quicksort. We conclude with suffix sorting and related applications.
6 个视频 (总计 85 分钟), 1 个阅读材料, 1 个测验
周4
完成时间为 2 小时
Tries
In this lecture we consider specialized algorithms for symbol tables with string keys. Our goal is a data structure that is as fast as hashing and even more flexible than binary search trees. We begin with multiway tries; next we consider ternary search tries. Finally, we consider character-based operations, including prefix match and longest prefix, and related applications.
3 个视频 (总计 75 分钟), 2 个阅读材料, 1 个测验
完成时间为 5 小时
Substring Search
In this lecture we consider algorithms for searching for a substring in a piece of text. We begin with a brute-force algorithm, whose running time is quadratic in the worst case. Next, we consider the ingenious Knuth−Morris−Pratt algorithm whose running time is guaranteed to be linear in the worst case. Then, we introduce the Boyer−Moore algorithm, whose running time is sublinear on typical inputs. Finally, we consider the Rabin−Karp fingerprint algorithm, which uses hashing in a clever way to solve the substring search and related problems.
5 个视频 (总计 75 分钟), 1 个阅读材料, 2 个测验
周5
完成时间为 2 小时
Regular Expressions
A regular expression is a method for specifying a set of strings. Our topic for this lecture is the famous grep algorithm that determines whether a given text contains any substring from the set. We examine an efficient implementation that makes use of our digraph reachability implementation from Week 1.
5 个视频 (总计 83 分钟), 2 个阅读材料, 1 个测验
完成时间为 5 小时
Data Compression
We study and implement several classic data compression schemes, including run-length coding, Huffman compression, and LZW compression. We develop efficient implementations from first principles using a Java library for manipulating binary data that we developed for this purpose, based on priority queue and symbol table implementations from earlier lectures.
4 个视频 (总计 80 分钟), 1 个阅读材料, 2 个测验
周6
完成时间为 1 小时
Reductions
Our lectures this week are centered on the idea of problem-solving models like maxflow and shortest path, where a new problem can be formulated as an instance of one of those problems, and then solved with a classic and efficient algorithm. To complete the course, we describe the classic unsolved problem from theoretical computer science that is centered on the concept of algorithm efficiency and guides us in the search for efficient solutions to difficult problems.
4 个视频 (总计 40 分钟), 2 个阅读材料, 1 个测验
完成时间为 1 小时
Linear Programming (optional)
The quintessential problem-solving model is known as linear programming, and the simplex method for solving it is one of the most widely used algorithms. In this lecture, we given an overview of this central topic in operations research and describe its relationship to algorithms that we have considered.
4 个视频 (总计 61 分钟), 1 个阅读材料, 1 个测验
完成时间为 2 小时
Intractability
Is there a universal problem-solving model to which all problems that we would like to solve reduce and for which we know an efficient algorithm? You may be surprised to learn that we do no know the answer to this question. In this lecture we introduce the complexity classes P, NP, and NP-complete, pose the famous P = NP question, and consider implications in the context of algorithms that we have treated in this course.
预备知识
你需要熟悉Java编程和“算法,第一部分”中的算法和数据结构。这门课主要针对的是对工程或科学感兴趣的大一大二学年本科生,以及对编程具有兴趣和一定基础的高中学生及专业人员。
参考资料
虽然这门课被设计为自给自足式的,但希望在七周课程以外扩展所学知识的同学,可以在我们编写的教材中找到更深入广泛的相关内容:《算法》第四版,艾迪生韦斯利出版社出版。
常见问题
本课程会讲到哪些算法和数据结构?
第一部分将集中探讨基础数据结构、排序、查找。主题包括:并查算法、二分查找、栈、队列、背包、插入排序、选择排序、希尔排序、快速排序、三路快排、归并排序、堆排序、二分堆、二分查找树、红黑树、分离链接和线性探测哈希表、Graham扫描、kd树。
第二部分将集中探讨图和字符串处理算法。主题包括:深度优先搜索、宽度优先搜索、拓扑排序、Kosaraju-Sharir算法、Kruskal算法、Prim算法、Dijkistra算法、Bellman-Ford算法、Ford-Fulkerson算法、LSD基数排序算法、MSD基数排序算法、三路基数快排算法、多路trie算法、三元查找trie算法、Knuth-Morris-Pratt算法、Boyer-Moore算法、Rabin-Karp算法、正则匹配、行程长度编码、Huffman编码、LZW压缩、Burrows-Wheeler变换。
网上还有其它相关资源吗?
有,我们的免费图书网站包含教材概要、网络练习、所有相关算法的Java实现(提供一键下载)、测试数据以及很多其它资源。
这门课同“算法设计与分析”课程有何不同?
两门课是互补的,这门课更强调编程和代码开发,而那门课更注重数学和证明。这门课侧重于在实际应用的实现和测试中学习各种算法,而那门课侧重于在解释算法为何有效的数学建模中学习算法。在典型计算机科学课程设计中,这门课针对的是大一和大二学生,而那门课针对的是大三和大四学生。
我想选“算法,第二部分”,但我错过了“算法,第一部分”。我该怎么做?
这就要看你的基础了。如果你对基本数据类型和经典排序、查找算法一无所知,你最好是等到下次第一部分开课时进行学习。如果你对基础知识比较熟悉,你也许能够通过研读我们的书籍和图书网站跟上进度。
我不是计算机专业学生,这门课适合我吗?
没问题,这门课适用于任何希望使用计算机解决大型问题的人(因为大型问题需要高效算法)。在普林斯顿的所有学生中,有超过25%的人选过这门课,包括工程、生物、物理、化学、经济等诸多其它专业的学生。选修这门课的远远不只是计算机科学专业的学生。
不熟悉Java编程的话,能选这门课吗?
我们的核心理念是,算法在实现和测试中是最容易理解的。Java在这里只是用于说明,我们在代码中特意避开了稀奇古怪的内容。就算你使用其它语言,这门课的代码你也应该能轻松适应。不过,我们要求这门课的编程作业用Java提交。如果你有其它语言的编程经验,通过我们的教材《Java编程导论:跨学科研究方法》及相关免费图书网站来学习我们的编程模型对你应该会有帮助。
没有任何编程基础的话,还能选这门课吗?
也许不行。