According to Union by size, each node x which has the size of the subtree rooted at x is stored. In UNION, the tree of the smaller set is made the subtree of the other tree and the size field of the root of the resulting tree is updated. According to path compression heuristics, the parent pointer is reset from x such that it points to the root for the find operation. Let the number of nodes be n and the number of finds be m. The union operations are executed before the find operations, so a tree is constructed before any operation. There are at most O(n) union operations and each union operation takes O (1) time. Thus, the total cost of union is O(n). The cost of a find operation is the increment of the number of new children to the root by 1. Each find operation will take O(m) time. So, the total cost of m find operation is O (m + n). Here, n = 1 + max (number of children of the root) Solution According to Union by size, each node x which has the size of the subtree rooted at x is stored. In UNION, the tree of the smaller set is made the subtree of the other tree and the size field of the root of the resulting tree is updated. According to path compression heuristics, the parent pointer is reset from x such that it points to the root for the find operation. Let the number of nodes be n and the number of finds be m. The union operations are executed before the find operations, so a tree is constructed before any operation. There are at most O(n) union operations and each union operation takes O (1) time. Thus, the total cost of union is O(n). The cost of a find operation is the increment of the number of new children to the root by 1. Each find operation will take O(m) time. So, the total cost of m find operation is O (m + n). Here, n = 1 + max (number of children of the root).