26.3 Find The Best Pseudocode

The pseudocode representation is the most precise and mathematically correct description of an algorithm. But obviously there are many different pseudocode representations for the same algorithm. How do we find the pseudocode description that is best for our educational purpose?

To illustrate our point consider two possible pseudocode descriptions of the "bucket sort" algorithm:

1. Full pseudocode, mathematically correct:
	n <-length[A]
	for i <- 1 to n
	  do insert A[i] into list B[nA[i]]
	for i <- 0 to n-1
	  do sort list B[i] with insertion sort
	concatenate the lists B[0],B[1],...,B[n-1] together in order
2. Abbreviated pseudocode, emphasizing the main steps:
	select input
	distribute elements into buckets
	sort buckets
	concatenate elements from buckets

The first pseudocode description comes directly from [Cor90]. It describes very clearly and very compactly what the algorithm does. But for the student's understanding of what bucket sort is really about, the second description is much more helpful. It is not mathematically exact and it would be impossible to automatically generate executable code out of it, but it teaches the fundamental concept. First the elements to be sorted are distributed into buckets, then the elements in each bucket are sorted separately, and finally the sorted elements of each bucket are concatenated into the sorted output list.

We claim that because of educational reasons both descriptions are necessary. To exactly specify what bucket sort is, we need the first description. But every effort should also be made to find an common sense description of the actions in the algorithm. By complementing each other, the two descriptions give the student an intuitive and mathematically sound understanding of the inner workings of the algorithm.