Posts

Showing posts with the label quicksort

I guess they know algorithms well, but...

The authors of Introduction to Algorithms (Cormen et al.) do not seem to  be much up on their software engineering. I suggest the foremost principle of software engineering is DRY: don't repeat yourself. Every time you repeat a bit of code, you double your maintenance worries. These authors, while they are no doubt experts on algorithms, knowing far more than me on that topic, seem to pay little attention to the DRY principle. For instance, when they want to introduce students to a random quicksort, after having explained a basic quicksort, they write a whole new function that is identical to basic quicksort, except that it calls random_partition() instead of partition(). Shouldn't students be taught to just pass in a partition function to quicksort()? Similarly, in dealing with heapsort, the authors suggest having max_heapify() and min_heapify() functions. Well, what about just writing heapify(), and passing it a comparison operator? Yes, certainly these points are per...