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

[bug] Implicit treap is not randomized #44

Open
ongyiumark opened this issue Sep 24, 2024 · 3 comments
Open

[bug] Implicit treap is not randomized #44

ongyiumark opened this issue Sep 24, 2024 · 3 comments

Comments

@ongyiumark
Copy link
Contributor

The implicit treap does not use the priority in the nodes anywhere, so it's not randomized, which results in a very unbalanced tree. We don't get the advantage of having logarithmic height, so running time is very slow.

@leloykun
Copy link
Contributor

Hi @ongyiumark !

iirc, this was actually an optimization trick

The merge operation is already size-aware (i.e. we merge the smaller subtree to the larger subtree). This "guarantees" logarithmic height in the average case.

The priority is only useful on init so we could start with a log-height tree.

Homeworks:

  1. Prove that this implementation "works" in the average case anyway
  2. Write a test case that breaks the implementation

@ongyiumark
Copy link
Contributor Author

Okay, we probably need to look more into this.

I tested it on a MHC problem, and it ran significantly faster when I used the priority for merging.

@leloykun
Copy link
Contributor

Oooh, can you write a PR for your codes?

(btw, starting now, I'll let you merge stiff w/o tests. I trust you. Just don't break anything!)

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