refactored graph construction and added find all predecessors algo