algorithm for finding cores and periphery of a graph