void function ( int arg0 , int arg1 ) { if ( isConnected ( arg0 , arg1 ) ) { System . out . println ( arg0 + "srini_string" + arg1 + "srini_string" ) ; return ; } int loc0 = list [ arg0 ] ; int loc1 = list [ arg1 ] ; for ( int loc2 = 0 ; loc2 < list . length ; loc2 ++ ) { if ( list [ loc2 ] == loc0 ) { list [ loc2 ] = loc1 ; } } }
connect two non-connected elements . while connecting two elements , we also need to make rest of the elements in first component gets updated to the value of second element so that we know all these elements are part of one component . time complexity : o n for each union operation . so for n union operations , time complexity with quadratic o n ^ 2 concode_field_sep int[] list concode_field_sep boolean isConnected concode_elem_sep void main