added LF algorithm for adj matrix graph