Overview
We illustrate our basic approach to developing and analyzing algorithms by considering the dynamic connectivity problem.
We will learn the union-find data type and several implementations(quick find, quick union, weighted quick union, weighted quick union with path compression).Finally, we apply the union-find data type to the percolation problem from physical chemistry.
So what is dynamic connectivity problem?
Steps to developing a usable algorithms(scientific approach)
1.Model the problem, try to understand, basically, what are the main elements of the problem that need to be solved.
2.Find an algorithm to solve it.
3.Fast enough?Fits in memory?
4.If not, figure out why.
5.Find a way to address the problem
6.Iterate until satisfied.
dynamic connectivity
Given a set of N objects.
Union command:connect two objects.
Find/connected query:is there a path connecting two object?
In part two of the course, we'll consider algorithms that explicitly find paths(more work to do).
Modeling the objects
Applications involve manipulating objects of all types.
- Pixels in a digital video.
- Computers in a network.
- Friends in a social network.
- Transistors in a computer chip.
- Elements in a mathematical set.
- Variable names in Fortran Programs.
- Metallic sites in a computer system.
When programming, convenient to name objects 0 to N-1
- Use integers as array index.
-
Suppress details not relevant to union-find.
Modeling the connections
We assume "is connected to" is an equivalence relation:
Reflexive:p is connected to p.
Symmetirc:if p is connected to q, then q is connected to p.
Transitive:if p is connected to q and q is connected to r, then p is connected to r.
Connected components. Maximal set of objects that are mutually connected
Implementing the operations
Find query.Check if two objects are in the same component.
Union command.Replace components containing two objects with their union.