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

Fix critical time complexity issue of queue operation in python and javascript #6220

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

DingChiLin
Copy link
Contributor

Fixes issue:
A standard Queue data structure should have O(1) time complexity for all basic operations.

Since the following two operations take O(N) time:
self.data.insert(0, x) in python
store.shift(); in javascript

The time complexity of some enqueue and dequeue operation will become O(N) instead of O(1)

Changes:

Major:

  1. Rewrite the python and javascript implementation of queue and fix the time complexity issue of enqueue and dequeue from O(N) to O(1).
  2. This implementation need users to decide the queue size at initialization.

Minor:

  1. Add top operation for getting the top element from queue.
  2. remove unrelated dependencies (array) in python implementation.

…ript implementation

1. Fix the time complexity of `enqueue` and `dequeue` from O(N) to O(1)
2. Add `top` operation for getting the top element from queue
3. remove unrelated dependencies
@AdiChat
Copy link
Member

AdiChat commented Oct 20, 2021

Looks great 😍

Thank you for your contribution.

If you would like to join our internship program and contribute to OpenGenus IQ, let us know and we will be happy to have you onboard

Hope you are enjoying your journey 🚆 with OpenGenus

@AdiChat AdiChat merged commit 116d62e into OpenGenus:master Oct 20, 2021
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

Successfully merging this pull request may close these issues.

2 participants