Open In App

Top | MCQs on Graph Data Strcuture with Answers | Question 38

Last Updated : 22 May, 2023
Like Article
Like
Save
Share
Report

Given a disjoint-set forest with N elements, what is the maximum height of the trees in the forest after M union operations if union by rank and path compression techniques are used?

(A)

O(M)

(B)

O(logM)

(C)

O(N)

(D)

O(N + M)


Answer: (B)

Explanation:

Using union by rank and path compression, the maximum height of the trees in the forest after M union operations is logarithmic with respect to M, resulting in a time complexity of O(log M).


Quiz of this Question
Please comment below if you find anything wrong in the above post


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads