Is Sedgewick's a good book to follow?

Printable View

• 04-05-2004
anoopks
Is Sedgewick's a good book to follow?
I am sorry, if this is a wrong question in this forum.

It has been quite a while since I have coded in C and last week, I decided to finish atleast one Algo book cover to cover(or atleast try), thus revising C. I picked up Sedgewick on the advice of a few friends and also ACCU review.

But is the book really good? Does the code in it work?

I tried running a few and already there are so many errors. I started with the 4th chapter and the code on Josephes election, reversing the list etc are already not working. Infact in solving Josephes election problem using a circular list, I rubbed my eyes when I saw

N--

right at the end of the code, which was there for I dont know why.

Never mind the silly naming style of the variables. Any opinions?

Thanks and I am sorry again if it was not the right forum.

Anoop.
• 04-05-2004
Prelude
>But is the book really good?
Yes, it is.

>Does the code in it work?
No. Sedgewick is a believer in reusing previous work, so most of the code is a poor Pascal to C conversion. If you want solid algorithms to write code from then I suggest Knuth's texts. Sedgewick gives excellent explanations, but his C code is just awful most of the time.

>which was there for I dont know why
I think you read the code wrong. My copy shows "N--;" inside of the last loop:
Code:

```while (x != x->next)   {     for (i = 1; i < M; i++) x = x->next;     x->next = x->next->next; N--;   } printf("%d\n", x->item);```
• 04-05-2004
anoopks
>I think you read the code wrong. My copy shows "N--;" inside of the last loop:

Precisely. I am also refering to the same statement. I am unable to comprehend the need for N--;

Anoop.
• 04-05-2004
Prelude
>I am unable to comprehend the need for N--;
Oh, I see. There is none, you can safely remove it. If N were used later for the number of items then decrementing it would make sense. But as it stands, there's no point.