Introduction to algorithms