Algorithmsi Exercises:unionfind

Source: Internet
Author: User

Question1

Give the id[] array that results from the following sequence of 6 unionoperations on a set of ten 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 ten integers, separated by whitespace. Recall:our Quick-find Convention for the Union operation P-q are to change Id[p] (and perhaps some other entries) but not I D[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's 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 ten 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 ten integers, separated by whitesp Ace.

Recall:when Joining, trees of equal size, our weighted Quick Union Convention are to
make the root of the SE Cond 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 n OT 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's 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 ten items? Check all the Apply.

Recall that we weighted Quick Union algorithm uses Union by size (number of nodes)
And not union by height.

Answer:choose the last of the last.

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 the tree rooted at the parent of 6 < twice the Size of the tree rooted at 6
 8 8 1 1 2 4 1 1 8 9 
correct 0.20 height of forest = 4 > LG N = LG (TEN)
 6 6 1 6 6 1 6 6 2 6 
< Span class= "Accessible-text-for-reader" >correct 0.20 6-7 0-7 1-5 2-8 5-8 4-7 6-2 7-3 2-9
Correct 0.20 2-1 0-3 2-6

Algorithmsi Exercises:unionfind

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.