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

Added Min Stack program #999

Merged
merged 2 commits into from
Nov 2, 2024
Merged

Added Min Stack program #999

merged 2 commits into from
Nov 2, 2024

Conversation

shuvojitss
Copy link
Contributor

@shuvojitss shuvojitss commented Nov 1, 2024

Pull Request for PyVerse 💡

Requesting to submit a pull request to the PyVerse repository.


Issue Title

Please enter the title of the issue related to your pull request.
Min Stack

  • I have provided the issue title.

Info about the Related Issue

What's the goal of the project?
Design a Data Structure MinStack that supports all the stack operations like push(), pop(), and an additional operation getMin() which should return minimum element from the MinStack. All these operations of MinStack must have a time complexity of O(1).

  • I have described the aim of the project.

Name

Please mention your name.
Shuvojit Samanta

  • I have provided my name.

GitHub ID

Please mention your GitHub ID.
shuvojitss

  • I have provided my GitHub ID.

Email ID

Please mention your email ID for further communication.
shuvojitsamanta15@gmail.com

  • I have provided my email ID.

Identify Yourself

Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
GSSOC

  • I have mentioned my participant role.

Closes

Enter the issue number that will be closed through this PR.
Closes: #993

  • I have provided the issue number.

Describe the Add-ons or Changes You've Made

Give a clear description of what you have added or modified.

Time Complexity Analysis

  • push(value):

    • The push operation is O(1) because it only involves a few comparisons and calculations, followed by an append operation to the list (stack), which is constant time.
  • pop():

    • The pop operation is O(1) because it only involves removing the top element from the stack and, if necessary, updating self.mini. List pop() for the last element in Python is O(1).
  • top():

    • The top operation is O(1) since it only accesses the last element of the list (stack) and possibly performs one comparison.
  • getmin():

    • The getmin operation is O(1) because it simply returns the current minimum value stored in self.mini.

Summary

Each operation in this MinStack implementation has a time complexity of O(1), making it efficient for stack operations with constant-time minimum retrieval.

  • I have described my changes.

Type of Change

Select the type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Describe how your changes have been tested.
I have tested it in all python editors and its working. I am providing a sample input output to describe it.

Sample Input

stack.push(7)
stack.push(12)
stack.getMin()
stack.push(4)
stack.getMin()
stack.pop()
stack.getMin()
stack.push(6)
stack.getMin()
stack.pop()
stack.top()

Sample Output:

Element Pushed: 7
Element Pushed: 12
Minimum Element in the stack is: 7
Element Pushed: 4
Minimum Element in the stack is: 4
Element popped: 4
Minimum Element in the stack is: 7
Element Pushed: 6
Minimum Element in the stack is: 6
Element popped: 6
Top Most Element is: 12

  • I have described my testing process.

Checklist

Please confirm the following:

  • My code follows the guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly wherever it was hard to understand.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added things that prove my fix is effective or that my feature works.
  • Any dependent changes have been merged and published in downstream modules.

Copy link

github-actions bot commented Nov 1, 2024

👋 Thank you for opening this pull request! We're excited to review your contribution. Please give us a moment, and we'll get back to you shortly!

Feel free to join our community on Discord to discuss more!

@UTSAVS26 UTSAVS26 added Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. Status: Approved PRs that have passed review and are approved for merging. level1 gssoc-ext labels Nov 2, 2024
@UTSAVS26 UTSAVS26 merged commit 1d82b44 into UTSAVS26:main Nov 2, 2024
1 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. gssoc-ext level1 Status: Approved PRs that have passed review and are approved for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Code Addition Request]: Min Stack
2 participants