[comp.lang.c] errors in Alg in "C" by Sedgewick

rogopp@attc.UUCP (Roger Opperman) (01/22/91)

In article <DAVIDD.91Jan19220640@wolf.cs.washington.edu> davidd@wolf.cs.washington.edu (David Doll) writes:
>Hello, I just got a copy of Algorithms in C by R. Sedgewick. I'm working with
>graph stuff and I typed in the alg on page 421 and my compiler (Ultrix 4.1 on
>a nDS5000) puked on almost everything I typed in...I doubled checked my typing
>so I'm guessing that he's wrong - has anybody else had problems with this
>book? Is there any place else that would have correct(?) code? Thanks.
>
>--
How well do you know C?  The text clearly states that the provided
code is only a fragment: "The types of v1 and v2 are omitted from this
program, as well as the code for index.  These can be added in a
straightforward manner, depending on the graph input representation
desired."  (p. 420).  It would be a little much to expect the code to
compile as "typed in" without a main and with no definition for v1, v2
and index.

kwolcott@cudnvr.denver.colorado.edu (01/22/91)

In article <DAVIDD.91Jan19220640@wolf.cs.washington.edu>, davidd@wolf.cs.washington.edu (David Doll) writes:
> Hello, I just got a copy of Algorithms in C by R. Sedgewick. I'm working with
> graph stuff and I typed in the alg on page 421 and my compiler (Ultrix 4.1 on
> a DS5000) puked on almost everything I typed in...I doubled checked my typing
> so I'm guessing that he's wrong - has anybody else had problems with this
> book? Is there any place else that would have correct(?) code? Thanks.
> 
> --
> David Doll
> Computer Science & Enginnering
> University of Washington
> Seattle, WA 98195
> M/S: FR-35
> davidd@cs.washington.edu

I read your posting with horror because I purchased this book with such
exhilaration some months ago and read through it never noticing any errors, but
not really typing in any code either.  I am appalled at the quality of the C
code on page 421!!!  I am not a great C programmer, but this half page of code
has an unbelievably large number of errors in it!  I think that these errors
can be partially attributed to blind/non-thinking translation from Pascal --
but some of these concepts would even have been right in Pascal either...I will
examine the older Pascal edition of this book to see how uncritical my reading
was there as well...

BTW, the errors I see I didn't need a compiler/lint to see -- these are quite
obvious and show a great deal of ignorance on the part of the person who wrote
this particular section (did the author really write this section or did he
farm it out to some STUPID [grad?] student?  I wish I could have gotten the
job -- I would have produced a far more professional result!)

Should one or more of us write to the author/publisher about this???

Kenneth A. Wolcott (also known as: "Mister Mountain Dew")......................
CU-Denver Computing Services,  Campus Box 169 /          boulder!pikes!kwolcott
1200 Larimer, NC2506, Denver CO 80204      //          kwolcott@cudenver.bitnet
P.O. Box 173364, Denver CO 80217-3364    /// kwolcott@pikes.denver.colorado.edu

gwyn@smoke.brl.mil (Doug Gwyn) (01/22/91)

In article <DAVIDD.91Jan19220640@wolf.cs.washington.edu>, davidd@wolf.cs.washington.edu (David Doll) writes:
> Hello, I just got a copy of Algorithms in C by R. Sedgewick. I'm working with
> graph stuff and I typed in the alg on page 421 and my compiler (Ultrix 4.1 on
> a DS5000) puked on almost everything I typed in...I doubled checked my typing
> so I'm guessing that he's wrong - has anybody else had problems with this
> book? Is there any place else that would have correct(?) code? Thanks.

Well, there are some problems with typing in JUST the supplied code,
as it does not include declarations for malloc() or scanf().  Also,
on p. 420 Sedgewick notes that v1, v2, and index() are omitted since
they depend on the graph representation.  Thus, you should use the
given code as a guide to writing your own, not just copy it blindly.

schmidt@oberkampf.ics.uci.edu (Doug Schmidt) (01/23/91)

There are more than just syntax errors in the code from Sedgewick's
book.  In fact, the section on regular expression pattern matching
contains both code *and* design that simply does not work (in
particular, the method he uses to build the state machine for the
alternation ('|') operation does not operate correctly).  When I
taught a compiler theory class I had to reimplement and redesign this
code in several places to avoid subtle bugs.  I'm curious whether
anyone knows how to contact Sedgewick, since I'd like to contribute my
corrections (written in C) for future versions of the book.

        Doug
--
``Cry havoc, and let slip           | Douglas C. Schmidt (schmidt@ics.uci.edu)
  the dogs of war.'' -- Marc Antony | (714) 856-4101

gwyn@smoke.brl.mil (Doug Gwyn) (01/24/91)

In article <1991Jan22.001229.20@cudnvr.denver.colorado.edu> kwolcott@cudnvr.denver.colorado.edu writes:
>BTW, the errors I see I didn't need a compiler/lint to see -- these are quite
>obvious and show a great deal of ignorance on the part of the person who wrote
>this particular section ...

While I don't claim that the code in question is particularly elegant,
I sure didn't see the vast number of problems that you claim.  Certainly,
as I previously reported, some standard headers should be included and as
the text on the preceding page said, graph representation details were
omitted.  That is all understandable in the context in which the code is
presented.  What other problems do you think are present?

On a related note, I was extremely disappointed with "Numerical Recipes
in C", wherein not only is some utterly horrible C coding employed, but
also the authors explicitly deride the very features of C that they
should have learned to use effectively before undertaking C coding.
I haven't studied Sedgewick's book enough to determine whether it has
similar problems.

glenn@suphys.physics.su.OZ.AU (Glenn Geers) (01/24/91)

From article <14939@smoke.brl.mil>, by gwyn@smoke.brl.mil (Doug Gwyn):

>[Stuff about Sedgewick deleted]

> 
> On a related note, I was extremely disappointed with "Numerical Recipes
> in C", wherein not only is some utterly horrible C coding employed, but
> also the authors explicitly deride the very features of C that they
> should have learned to use effectively before undertaking C coding.
> I haven't studied Sedgewick's book enough to determine whether it has
> similar problems.

I agree. They think that switch statements aren't a good feature!
Perhaps their C code is just machine translated FORTRAN (for the most part)
like the original Pascal code that was stuck in the back of early versions
of 'Numerical Recipes'.

Anyway long live the computed goto :-)
Cheers,
	Glenn

glenn@qed.physics.su.oz.au

--
Glenn Geers                       | "So when it's over, we're back to people.
Department of Theoretical Physics |  Just to prove that human touch can have
The University of Sydney          |  no equal."
Sydney NSW 2006 Australia         |  - Basia Trzetrzelewska, 'Prime Time TV'