Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 4 : O(1) enqueue and amortized O(1) dequeue / O(1) एनक्यू और परिशोधित O(1) डिक्यू
Advertisement
Detailed Solution
सही उत्तर O(1) enqueue and amortized O(1) dequeue / O(1) एनक्यू और परिशोधित O(1) डिक्यू है।
Key Points
Helpful?
Question:
A queue is implemented using two stacks. What are the time complexities of enqueue and dequeue? / दो स्टैक का उपयोग करके एक क्यू लागू की गई है। एनक्यू और डिक्यू की समय जटिलताएँ क्या हैं?
1.
O(n) enqueue and O(1) dequeue / O(n) एनक्यू और O(1) डिक्यू
2.
O(1) enqueue and O(n) amortized dequeue / O(1) एनक्यू और O(n) परिशोधित डिक्यू
3.
O(log n) for both operations / दोनों संक्रियाओं के लिए O(log n)
4.
O(1) enqueue and amortized O(1) dequeue / O(1) एनक्यू और परिशोधित O(1) डिक्यू
Correct Answer: O(1) enqueue and amortized O(1) dequeue / O(1) एनक्यू और परिशोधित O(1) डिक्यू
Enqueue pushes onto the input stack in O(1); each element moves to the output stack at most once, so dequeue costs O(1) amortized. / एनक्यू इनपुट स्टैक पर O(1) में पुश करता है; प्रत्येक अवयव आउटपुट स्टैक में अधिकतम एक बार जाता है, इसलिए डिक्यू की परिशोधित लागत O(1) है।
Downloaded from PrepSnap (prepsnap.in)