Q8. Consider the Stack ADT implemented using a Python list (called items) such that push() and pop() are defined as follows: def push(self, item): self.items.insert(0, item) def pop(self): return self.items.pop(0) What is the big-O complexity of push() and pop()? (A) both push() and pop() are O(n) (B) pop() is O(1) but push() is O(n) (C) push() is O(1) but pop() is O(n) (D) both push0 and pop() are O(n)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

question 8 i just need answer  please quikly thanks !

Q8. Consider the Stack ADT implemented using a Python list (called items) such that push() and
pop() are defined as follows:
def push(self, item):
self.items.insert(0, item)
def pop(sell):
return self.items.pop(0)
What is the big-O complexity of push() and pop()?
(A) both push() and pop() are O(n)
(B) pop() is O(1) but push() is O(n)
(C) push() is O(1) but pop() is O(n)
(D) both push() and pop() are O(n)
Transcribed Image Text:Q8. Consider the Stack ADT implemented using a Python list (called items) such that push() and pop() are defined as follows: def push(self, item): self.items.insert(0, item) def pop(sell): return self.items.pop(0) What is the big-O complexity of push() and pop()? (A) both push() and pop() are O(n) (B) pop() is O(1) but push() is O(n) (C) push() is O(1) but pop() is O(n) (D) both push() and pop() are O(n)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning