Algorithms: Design and Analysis