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

Question about treap insertion pseudo code, chapter 3, page 84 #34

Open
sroccaserra opened this issue Mar 11, 2024 · 0 comments
Open

Question about treap insertion pseudo code, chapter 3, page 84 #34

sroccaserra opened this issue Mar 11, 2024 · 0 comments

Comments

@sroccaserra
Copy link

sroccaserra commented Mar 11, 2024

Hi, this is a question about the book, I hope it's ok if I file it here.

I'm implementing the treap data structure from chapter 3, and I have problems making the insertion code work, page 84.

In particular, these lines of the pseudo-code seems contradictory to the text describing it.

The code:

  if node.key <= key then
    node ← node.left
  else
    node ← node.right

The description:

Checks how the new key compares to current node’s key; if it’s not larger, we take the left branch.

It seems that in the code we take the left branch if the new key is larger, contrary to the description.

My tests also seem to show me that making the code match the description seems to work as intended, so it seems the description is right, not the code (?) Please test further if relevant.

  if key <= node.key then
    node ← node.left
  else
    node ← node.right

Also, suggestion: maybe avoiding negative formulation like "if it's not larger" would make the description easier to understand ?

Thank you for the book, I hope this helps if I spotted a mistake, and I hope to learn something if I'm wrong and I misunderstood a part of the implementation. Sorry if it was reported before, I did not find it in the erratum.

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

1 participant