Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON PLEASE TEST CASES NEED TO BE PRINTED TO USER PROBLEM STATEMENT: In today s Lab we will explore ways to design a Stack

IN PYTHON PLEASE
TEST CASES NEED TO BE PRINTED TO USER
PROBLEM STATEMENT:
In todays Lab we will explore ways to design a Stack with O(1) lookup time of the Minimum element. You will solve the problem as stated below:
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Implement the MinStack class:
MinStack initializes the stack object.
push(int val) pushes the element val onto the stack.
pop() removes the element on the top of the stack.
top() gets the top element of the stack.
getMin() retrieves the minimum element in the stack.
You must implement a solution with O(1) time complexity for each solution.
Very Very Important:
1.(1) Your code should be well commented which explains all the steps you are
performing to solve the problem. A submission without code comments will immediately be deducted 15 points!
2.(2) As a comment in your code, please write your test-cases on how you would test your solution assumptions and hence your code.
A submission without test cases (as comments) will immediately be de- ducted 15 points!
Please Remember: Although, written as comments - You will address your test cases in PROBLEM STATEMENT:
In today's Lab we will explore ways to design a Stack with O(1) lookup time of the Minimum
element.
You will solve the problem as stated below:
Design a stack that supports push, pop, top, and retrieving the minimum element in constant
time. Implement the MinStack class:
MinStack initializes the stack object.
push(int val) pushes the element val onto the stack.
pop() removes the element on the top of the stack.
top() gets the top element of the stack.
) retrieves the minimum element in the stack.
You must implement a solution with O(1) time complexity for each solution.
Very Very Important:
(1) Your code should be well commented which explains all the steps you are
performing to solve the problem. A submission without code comments will immediately
be deducted 15 points!
(2) As a comment in your code, please write your test-cases on how you would test your
solution assumptions and hence your code.
A submission without test cases (as comments) will immediately be de- ducted 15 points!
Please Remember: Although, written as comments - You will address your test cases in
the form of code and not prose the form of code and not prose
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

sharing of non-material benefits such as time and affection;

Answered: 1 week ago