In the coursera course, below union find is implemented for numbers only: https://www.coursera.org/learn/introduction-to-algorithms/lecture/EcF3P/quick-find
public class QuickFindUF
{
private int[] id;
public QuickFindUF(int N)
{
id = new int[N];
for (int i = 0; i < N; i++)
id[i] = i;
}
public boolean connected(int p, int q)
{ return id[p] == id[q]; }
public void union(int p, int q)
{
int pid = id[p];
int qid = id[q];
for (int i = 0; i < id.length; i++)
if (id[i] == pid) id[i] = qid;
}
}
At the end of the slide, how are 10^9 operations per second and other 10^x numbers calculated (including 10)? All numbers are in below image: (text is also copied below)
Rough standard (for now).
- 10^9 operations per second.
- 10^9 words of main memory.
- Touch all words in approximately 1 second.
Ex. Huge problem for quick-find.
- 10^9 union commands on 10^9 objects.
- Quick-find takes more than 10^18 operations.
- 30+ years of computer time!