Exercise for the algorithms course