I have the following algorithm for detecting a cycle in an undirected graph with a set E of n edges :
for each unvisited edge (u, v) in E:
{
if(Find(u) = Find(v)) // u and v belong to the same set already
{
print "Cycle Detected";
break;
}
else
{
Union(u, v); // put u and v in the same set
}
}
my question is can I implement the union-find by size and path compression method and then claim that the time complexity of the code is O(n log*(n)) worst case?