I think there r some steps which r not necessary such as:

1)-> while uniting we need not to find the sup(x) because at the end the parent(x) is to be sup(y) so why do we need to check is sup(x)==sup(y) or not…

2)-> the sup(x+1) is always > sup(x) so why we r finding the max(sup(x) , sup(x+1)…

@kaushikjatin,

  1. Because there’s no point in uniting if par[x]==par[y].
  2. Because then we can call, merge(i,i+1) as well as merge(i+1,i), the order wouldn’t matter.