In Introduction to Algorithms, by Thomas Cormen, there are some algorithm like in this image. With one column for the code, one for the cost and one for the times.
I searched a lot, but I didn't find how to do it.
algorithms
In Introduction to Algorithms, by Thomas Cormen, there are some algorithm like in this image. With one column for the code, one for the cost and one for the times.
I searched a lot, but I didn't find how to do it.
Best Answer
This is what I'd do, if I were not to use
clrscode
.Please, notice a few things:
There are three widths (in centimeters) that may need tweaking.
The costs of
for
andwhile
statements are inside the brackets and there must not be any space between them and the closing bracket. This is a bit fragile. The same forif
and all other block statements.The cost of line 3 is displayed next to the first of the two lines, not the second (as in the original). It was easier like this, but I think I also prefer it.
This answer takes the opposite route from Jubobs's answer, which is using the
clrscode
package. If you prefer to useclrscode
, I'm sure you'll find the way to properly use|>
for tabbing the extra columns, although it's not well documented. Also, it may be preferable for other reasons too, if you want your algorithms to look exactly like those in the book.