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

Can we append better? #12

Open
treeowl opened this issue Aug 12, 2020 · 1 comment
Open

Can we append better? #12

treeowl opened this issue Aug 12, 2020 · 1 comment
Labels
help wanted Extra attention is needed performance

Comments

@treeowl
Copy link
Owner

treeowl commented Aug 12, 2020

It seems plausible that we could append queues in O(min(m,n)) time rather than O(m+n) time. Can we append stacks faster too? Maybe O(m) time?

@treeowl
Copy link
Owner Author

treeowl commented Aug 12, 2020

For stacks, I think I see a path. If the first argument is deeper than the second (or the same depth), I don't think we can do anything very interesting; everything has to be restructured. But if the first argument is shallower, I think there's quite a bit more potential. Let's think about adding the shapes of two stacks. We need to use carries of up to 3 until the first stack runs out. The step after that, we may have to carry 2. But in the next step, we need to carry at most 1. So we can rebuild the elements of the first stack and an initial segment of the second stack into a fresh stack initial segment plus (possibly) an extra array to insert below. So all in all, m <> n should take O(|m|). It's going to be a bear to implement though...

@treeowl treeowl added the help wanted Extra attention is needed label Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed performance
Projects
None yet
Development

No branches or pull requests

1 participant