Design and Analysis of Algorithms