14.6 Exercises
Last updated
Last updated
Problem 2 from the Spring 2016 Midterm 2.
Problem 1d from the Spring 2015 Midterm 2.
Suppose we have the following WQU with path compression. What is the height of the tree after we call isConnected(8, 9)
?
Which of the following arrays could represent a valid weighted quick union structure?
Define a fully connected WQU as one where all elements are in the same set. What is the maximum and minimum height of a fully connected WQU with 6 elements?
Suppose we have a WQU of height H. What is the minimum number of elements that must be in the WQU?
Problem 3 from the Spring 2017 Midterm 2.
Write a int find(int p)
method for the WQU with path compression. It should perform path compression as described in lecture: any node on the path from root to our target node should have its parent reset to the root. It takes in the target node p
and returns the root of the tree p
is in.
[4, -8, 8, 2, 1, -2, 1, 1, 4, 5]
: invalid. The maximum height is .
The minimum height is always 1 (all elements are connected to the root). The maximum height is 2 (we take the floor of ).
We know that , where is the number of elements in the WQU. As such, .
Suppose we create a WQU with items, then we perform union operations and union operations. Using big O notation, what is the runtime of this sequence of operations?
Using the same variables as problem 2, describe a sequence of operations that would result in a runtime of .
. Each operation takes time, and we need time to initialize an empty array of size .