Algorithm Day 1
- To get understand the impact of algorithm.
- Know about the problem of “Dynamic connectivity”
Learned there are three ways to solve this problem:
- Quick find, Quick Union,
- Weighted Quick union,
- Weighted Quick union with path compression
Steps to developing a usable algorithm
- Model the problem.
- Find an algorithm to solve it.
- Fast enough? Fits in memory?
- If not, figure out why.
- Find a way to address the problem.
- Iterate until satisfied.
The scientific method.
Mathematical analysis.
Q1: So, How to solve the Kruskal’s minimum spanning tree with union-find ?
Q2: Social network connectivity. Given a social network containing n members and a log file containing m timestamps at which times pairs of members formed friendships, design an algorithm to determine the earliest time at which all members are connected (i.e., every member is a friend of a friend of a friend … of a friend). Assume that the log file is sorted by timestamp and that friendship is an equivalence relation. The running time of your algorithm should be m*log n or better and use extra space proportional to n.
Q3: Search in a bitonic array. An array is bitonic if it is comprised of an increasing sequence of integers followed immediately by a decreasing sequence of integers. Write a program that, given a bitonic array of n distinct integer values, determines whether a given integer is in the array.
- Standard version: Use ∼3lgn compares in the worst case.
- Signing bonus: Use ∼2lgn compares in the worst case (and prove that no algorithm can guarantee to perform fewer than ∼2lgn compares in the worst case).