I need help understanding the explanations given by the questions about weighted quick union:
Which of the following
id[]
array(s) could be the result of running the weighted quick union algorithm on a set of10
items? Check all that apply.Recall that our weighted quick union algorithm uses union by size (number of nodes) (and not union by height).
Incorrect:
9 1 7 3 4 9 6 7 8 9
Explanation:9-5 7-2 5-0
Incorrect:
2 2 2 2 5 1 2 3 1 2
Explanation:2-9 3-7 9-3 5-4 0-2 1-8 8-4 4-9 8-6
Correct:
9 9 3 4 9 4 9 9 4 2
Explanation: Theid[]
array contains a cycle:2->3->4->9->2
Correct:
0 2 3 0 0 2 2 9 3 0
Explanation: Size of tree rooted at parent of2 <
twice the size of tree rooted at2
Correct:
0 4 6 7 4 1 5 1 7 3
Explanation: Height of forest =4 > lg N = lg(10)
- How am I supposed to know the actual union operations as shown by the first two problems?
- Do I have to look at every element to figure out if there is a cycle?
- How do I know the size of a tree? (BTW The explanation given in the fourth problem makes no sense to me)
- How do I know the height of a forest?