Question1

Give the id[] array that results from the following sequence of 6 unionoperations on a set of 10 items using the quick-find algorithm. 6-3 2-3 5-3 5-1 9-3 3-0 Your answer should be a sequence of 10 integers, separated by whitespace.Recall: our quick-find convention for the union operation p-q is to change id[p](and perhaps some other entries) but not id[q].

Answer: 0 0 0 0 4 0 0 7 8 0

Question Explanation
The correct answer is: 0 0 0 0 4 0 0 7 8 0

Here is the id[] array after each union operation:

0 1 2 3 4 5 6 7 8 9
6-3: 0 1 2 3 4 5 3 7 8 9
2-3: 0 1 3 3 4 5 3 7 8 9
5-3: 0 1 3 3 4 3 3 7 8 9
5-1: 0 1 1 1 4 1 1 7 8 9
9-3: 0 1 1 1 4 1 1 7 8 1
3-0: 0 0 0 0 4 0 0 7 8 0


Question 2

Give the id[] array that results from the following sequence of 9 union
operations on a set of 10 items using the weighted quick-union algorithm from lecture.

7-9 9-4 7-0 8-1 3-7 5-6 5-1 3-8 2-6

Your answer should be a sequence of 10 integers, separated by whitespace.

Recall: when joining two trees of equal size, our weighted quick union convention is to
make the root of the second tree point to the root of the first tree. Also, our weighted
quick union algorithm performs union by size (number of nodes) - not union by height -
and does not do path compression.

Answer: 7 8 7 7 7 7 5 7 5 7
Question Explanation
The correct answer is: 7 8 7 7 7 7 5 7 5 7

Here is the id[] array after each union operation:

0 1 2 3 4 5 6 7 8 9
7-9: 0 1 2 3 4 5 6 7 8 7
9-4: 0 1 2 3 7 5 6 7 8 7
7-0: 7 1 2 3 7 5 6 7 8 7
8-1: 7 8 2 3 7 5 6 7 8 7
3-7: 7 8 2 7 7 5 6 7 8 7
5-6: 7 8 2 7 7 5 5 7 8 7
5-1: 7 8 2 7 7 5 5 7 5 7
3-8: 7 8 2 7 7 7 5 7 5 7
2-6: 7 8 7 7 7 7 5 7 5 7


Question 3

Which of the following id[] array(s) could be the result of running the weighted quick union
algorithm on a set of 10 items? Check all that apply.

Recall that our weighted quick union algorithm uses union by size (number of nodes)
and not union by height.

Answer: Choose the last two.

Your Answer   Score Explanation

5 5 5 5 2 6 4 5 2 3

Correct 0.20 The id[] array contains a cycle: 6->4->2->5->6
5 3 6 6 6 5 5 8 6 6 
Correct 0.20 Size of tree rooted at parent of 6 < twice the size of tree rooted at 6
8 8 1 1 2 4 1 1 8 9 
Correct 0.20 Height of forest = 4 > lg N = lg(10)
6 6 1 6 6 1 6 6 2 6 
Correct 0.20 6-7 0-7 1-5 2-8 5-8 4-7 6-2 7-3 2-9
0 2 2 0 4 5 2 7 8 9 
Correct 0.20 2-1 0-3 2-6

AlgorithmsI Exercises: UnionFind的更多相关文章

  1. AlgorithmsI Exercises: Analysis of Algorithms

    Question 1 Suppose that you time a program as a function of N and producethe following table. N seco ...

  2. Union-Find 检测无向图有无环路算法

    不相交集合数据结构(Disjoint-set data structure)是一种用于跟踪集合被分割成多个不相交的子集合的数据结构,每个集合通过一个代表来标识,代表即集合中的某个成员. Union-F ...

  3. UVA - 11987 Almost Union-Find[并查集 删除]

    UVA - 11987 Almost Union-Find I hope you know the beautiful Union-Find structure. In this problem, y ...

  4. 并查集(union-find)算法

    动态连通性 . 假设程序读入一个整数对p q,如果所有已知的所有整数对都不能说明p和q是相连的,那么将这一整数对写到输出中,如果已知的数据可以说明p和q是相连的,那么程序忽略p q继续读入下一整数对. ...

  5. UVa 11987 Almost Union-Find(支持删除操作的并查集)

    传送门 Description I hope you know the beautiful Union-Find structure. In this problem, you’re to imple ...

  6. 有一种算法叫做“Union-Find”?

    前言: 不少搞IT的朋友听到“算法”时总是觉得它太难,太高大上了.今天,跟大伙儿分享一个比较俗气,但是却非常高效实用的算法,如标题所示Union-Find,是研究关于动态连通性的问题.不保证我能清晰的 ...

  7. Union-Find Algorithm

    Union-Find Algrithm is used to check whether two components are connected or not. Examples: By using ...

  8. 并查集 Union-Find

    并查集能做什么? 1.连接两个对象; 2.查询两个对象是否在一个集合中,或者说两个对象是否是连接在一起的. 并查集有什么应用? 1. Percolation问题. 2. 无向图连通子图个数 3. 最近 ...

  9. 最小生成树--Prim算法,基于优先队列的Prim算法,Kruskal算法,Boruvka算法,“等价类”UnionFind

    最小支撑树树--Prim算法,基于优先队列的Prim算法,Kruskal算法,Boruvka算法,“等价类”UnionFind 最小支撑树树 前几节中介绍的算法都是针对无权图的,本节将介绍带权图的最小 ...

随机推荐

  1. myeclipse配置svn亲测

    1.安装目录更改为myeclipse install 目录:E:\MyEclipse85\MyEclipse 8.5common 目录:           E:\MyEclipse85\Common ...

  2. insert当 sql语句里面有变量 为字符类型的时候 要3个单引号

    set @InsertStr='INSERT INTO [dbo].[T_SchoolPercentMonth]([SchoolID],[MonthOfYear],[PercentNum]) VALU ...

  3. Linux命令行编辑快捷键

    Linux命令行编辑快捷键: history 显示命令历史列表 ↑(Ctrl+p) 显示上一条命令 ↓(Ctrl+n) 显示下一条命令 !num 执行命令历史列表的第num条命令 !! 执行上一条命令 ...

  4. Java集群之session共享解决方案

    随着互联网的日益壮大,网站的pv和uv成线性或者指数倍的增加.单服务器单数据库早已经不能满足实际需求.比如像盛大,淘宝这样的大型网络公司,更是如此.     集群,也就是让一组计算机服务器协同工作,达 ...

  5. Oracle主键自动生成_表and存储过程

    -- Create table create table T_EB_SYS_DN_SEQUENCE_CONFIG ( sequence_id VARCHAR2(36) default sys_guid ...

  6. Java封装的与当前时间比较,得到多少年,多少月,多少天前,多少小时前,多小分钟前

    public class CalendarCal { /**  * 与当前时间比较,得到多少年,多少月,多少天前,多少小时前,多小分钟前  *   * @param calendar  *       ...

  7. iOS7初体验(2)——单元测试

    在Xcode 4.6及以前的版本,一直觉得单元测试这部分功能做得很鸡肋,用起来感觉很别扭.这一次Xcode 5.0默认就引入了单元测试,赶快来看看看相比以前的版本有什么提升吧!~_~ 1.     首 ...

  8. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

  9. Java反射学习(java reflect)(二)

    ok之前说了Java的反射和反射分析类,那这些东西有神马作用呢,下面就来说应用: 三.运行时使用反射分析对象 简单写一个Employee类,然后利用JAVA反射去取name域,getDeclareFi ...

  10. 【转】WF4.0实战系列索引

    转自:http://www.cnblogs.com/zhuqil/archive/2010/07/05/wf4-in-action-index.html 此系列的工作流文件案例比较多点,实用性好. W ...