Week1-2Quick Find
来源:互联网 发布:hp c7000 网络配置 编辑:程序博客网 时间:2024/05/17 22:05
Quick Find(eager approach)
Data Structure
-Integer Array id[] of size N
-Interpretation: p and q are connected iff they have the same id
Example
Find
connected( p, q )
Check if p and q have the same id
Union
union( p, q )
To merger component containing p and q, change all entries whose id equals id[p] to id[q](a lot of entries whose value may be changed)
Quick Find Implementation
public class QuickFindUF { private int[] id; public QuickFindUF( int N ) { id = new int[N]; for( int i = 0 ; i < N; i++ ) { // Set id of each object to itself(N accesses) id[i] = i; } } public boolean connected( int p, int q ) { // Check if p and q are connected(2 accesses) return id[p] == id[q]; } public void union( int p, int q ) { // Change all entries with id[p] to id[q]( at most 2N+2 accesses) int pid = id[p], qid = id[q]; for( int i = 0; i < id.length; i++ ) { if( id[i] == pid ) { id[i] = qid; } } } }
Cost
Algorithm initialize union find quick-find O(N) O(N) O(1)
Union is too expansive!!!
Quadratic time algorithms are too slow, because they don’t scale with the technology.
0 0
- Week1-2Quick Find
- Week1-3Quick Union
- Quick-Find
- Quick Find
- week1、2
- Week1-5Union-Find Applications
- coursera Algorithms week1 练习测验2:Union-find with specific canonical element
- quick-find【连通图】
- CS229 Week1-2笔记
- week1
- week1
- week1
- week1
- week1
- week1
- 2.quick find and quick union
- 1.3:Union-Find算法-----quick-find算法
- union-find上(quick-find)算法
- Android之QQ授权登录获取用户信息
- win7的64位电脑如何配置使用Notebook?
- 构建ftp服务器(二)
- OC之i文件管理NSFileHandle
- 技术升级攻略
- Week1-2Quick Find
- C#做出验证码的例子
- miscdevice混杂设备驱动
- 比较并对比散列表和STL map。散列表是如何实现的?
- C++11 区间迭代
- 有关性能和误删的注意
- Struts2配置
- Ubuntu14.04下安装scrapy
- 去除字符串中的重复字符