all paths algorithm