The task is to find the time complexity in the worst case of m operations in Union-Find structure of "find" and "union", when all the "union" operations occur before all the "find" operations.
The union-find structure starts with n disjointed sets, that contain one element each. Moreover, each set is represented as a tree, and the structure uses path-compression and union-by-rank.
What i was thinking is that first of all, all the union operation together will take O(log(n)), because each one takes O(1), and there could occur not more than log(n) such operations.
After that if we look at the find elements then for each element the first find will take O(log(n)), but then the next time it will take O(1) for each element in its path. Therefore it will take less then O(m*log(n)).
I am not sure exactly how to continue from here. I thought that it will maybe take:
log(n) + log(n/2) + log(n/4) + .... = log(n)*log(n)
because every time the level of the path that we need to go up gets shorter.
However. I am not sure and also don't see where the m parameter is used here. Maybe there is also need to use the inverse Ackerman function in the analyze but I don't see how.
"find" operation (FindSet)
"union" operation
Time complexity