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. Realm Configuration HOW-TO--官方

    来源:https://secure.gettinglegaldone.com/docs/realm-howto.html Quick Start This document describes how ...

  2. iOS-设置状态栏白色以及覆盖状态栏

    iOS-设置状态栏白色以及覆盖状态栏 将状态栏设置为白色 首先, 在info.plist中添加一个标记. View controller–based status bar appearance键值设置 ...

  3. 关于 Android 进程保活,你所需要知道的一切

    早前,我在知乎上回答了这样一个问题:怎么让 Android 程序一直后台运行,像 QQ 一样不被杀死?.关于 Android 平台的进程保活这一块,想必是所有 Android 开发者瞩目的内容之一.你 ...

  4. SQL server 使用触发器跨数据库备份数据

    create database TriggerTest create table transInfo2 --交易信息表 ( cardID ) not null, --卡号 transType ) no ...

  5. 惠普 Compaq 6520s 无线开关打不开

    问题描述:键盘上面的无线开关怎么按都打不开,始终是出于黄色的状态   解决方法:尝试恢复bios默认值测试: 开机不停点击F10进入bios,选择File选项,选择Restore Defaults-- ...

  6. cookie防篡改

    概述: 除了 session 外,一般不会在客户端的 cookies 里保存过于重要的凭据,但电商应用有时候不可避免地存储了一些敏感数据到客户端,当然不希望被篡改. 目的: 让服务器端能识别cooki ...

  7. jquery 操作 checkbox

    对checkbox的其他几个操作 1. 全选2. 取消全选3. 选中所有奇数4. 反选5. 获得选中的所有值 js代码 $("document").ready(function() ...

  8. 向RichTextBox控件不停的AppendText数据时,如何把光标的焦点始终显示到最后

    上面是csdn上的一个网友的问题,我的一个实现如下://让文本框获取焦点this.richTextBoxInfo.Focus();//设置光标的位置到文本尾this.richTextBoxInfo.S ...

  9. Spring配置多数据源错误总结

    由于系统需要调用多个数据源包含mysql,sqlServe和Oracle,所以要在Spring的xml文件中配置多数据源,一下是配置过程中常见的错误: 1.配置的是mysql的数据源,却报oracle ...

  10. servlet从xml提取数据登陆

    在xml文档下可以设置参数的初始值,在这里把他当成了数据库在用 <servlet> <description>This is the description of my J2E ...