Created a findShortestPath method for traversing graphs.