This was a homework assignment for Algorithms and Data Structures.