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

✅ Two-Stack Enqueue and Dequeue (Lazy Transfer) #1553

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

yashksaini-coder
Copy link
Contributor

Fixes: #1498

Summary:

This PR provides, A complete C implementation of a queue using two stacks with detailed documentation explaining the approach and complexity. Also a flowchart showing the operation logic

  • The two-stack approach with lazy transfer provides efficient queue operations:
  • Enqueue: O(1) time complexity
  • Dequeue: O(1) amortized time complexity
  • Space complexity: O(n)

The lazy transfer strategy means we only move elements from the input stack to the output stack when necessary, which is more efficient than transferring on every operation.


@pankaj-bind can you review this PR, and assign this issue to me with proper labels

@yashksaini-coder
Copy link
Contributor Author

@pankaj-bind @can you review this PR, and add proper labels to it

@pankaj-bind pankaj-bind merged commit 6f60842 into AlgoGenesis:main Nov 2, 2024
1 of 2 checks passed
@yashksaini-coder yashksaini-coder deleted the yash/fix-1498 branch November 2, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NEW ALGORITHM] Two-Stack Enqueue and Dequeue (Lazy Transfer)
2 participants