Algorithms, Part I — Princeton University¶
Course: https://www.coursera.org/learn/algorithms-part1/home/welcome
Union Find¶
Dynamic connectivity problem — given a set of N objects, support:
Are objects p and q connected?
Connect objects p and q.
Union-find data type — implementations covered:
Quick Find
Quick Union
Weighted Quick Union
Weighted Quick Union with Path Compression
Application: Percolation — given a grid of open/blocked sites, determine whether fluid can percolate from top to bottom. Models problems in physical chemistry (electrical conductivity of composite materials, fluid flow through porous media).
A good algorithm (weighted quick union) makes the difference between solving this efficiently and not at all.
Resources¶
Queues¶
Programming assignment: http://coursera.cs.princeton.edu/algs4/assignments/queues.html
Programming Environment Setup¶
Java¶
If multiple JDKs are installed, set
JAVA_HOME:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
Princeton algs4 environment (Mac)¶
Install from http://algs4.cs.princeton.edu/mac/ — the algs4.app installer sets up:
Java 8 — verifies
javacandjavaversionsTextbook libraries —
algs4.jarat/usr/local/algs4/Checkstyle — code style checking (
checkstyle-algs4,checkstyle-cos226)FindBugs — static analysis (
findbugs-algs4,findbugs-cos226)DrJava — IDE with algs4 classpath preconfigured
Wrapper scripts —
java-algs4,javac-algs4,java-cos226,javac-cos226in/usr/local/bin/
Installation log: /usr/local/algs4/log.txt
Assignment submission¶
zip percolation.zip Percolation.java PercolationStats.java