Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect if statement condition in Insertion Sort Improvement 2 #44

Closed
po2xel opened this issue Sep 7, 2017 · 3 comments
Closed

Incorrect if statement condition in Insertion Sort Improvement 2 #44

po2xel opened this issue Sep 7, 2017 · 3 comments

Comments

@po2xel
Copy link

po2xel commented Sep 7, 2017

Hi @liuxinyu95 ,
Thanks for this open-source algorithm book. I am reading it and find an incorrect if statement condition in Insertion Sort Improvement 2.

\begin{algorithmic}
\Function{Insert}{$L, x$}
  \State $p \gets$ NIL
  \State $H \gets L$
  \While{$L \neq$ NIL $\land $ \Call{Key}{$L$} $<$ \Call{Key}{$x$}}
    \State $p \gets L$
    \State $L \gets $ \Call{Next}{$L$}
  \EndWhile
  \State \Call{Next}{$x$} $\gets L$
  \If{$p \neq$ NIL}                           // It should be \If{$p \eq$ NIL}, right?
    \State $H \gets x$
  \Else
    \State \Call{Next}{$p$} $\gets x$
  \EndIf
  \State \Return $H$
\EndFunction
\end{algorithmic}

Best Regards,

@po2xel
Copy link
Author

po2xel commented Sep 8, 2017

And the Red-Black tree in Figure 3.4: An example red-black tree is not correct. The leaf (NIL) isn't drawn as black as shown in the wiki page: https://en.wikipedia.org/wiki/File:Red-black_tree_example.svg
It leads to confusion when I read the properties and the example shown in Figure 3.4.

@liuxinyu95
Copy link
Owner

You are right.
I updated the insertion sort algorithm with this fix:
7d9891c

I'll next check the red-black tree figure issue.

@liuxinyu95
Copy link
Owner

I added a figure to shown the NIL nodes, then explain the reason why we'll ignore the black NIL nodes in the rest of the book. See the following commit:
8da19de

Here is the sample chapter with this change.
rbtree-en.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants