added connected components algorithm