Implements cheapest function for finding cheapest node in frontier