Data Structures and Algorithms

Language: Python

Challenge Type: Code Challenge / Algorithm

stack-queue-pseudo

Code

tests

Challenge11

  1. Create a brand new PseudoQueue class. Do not use an existing Queue. Instead, this PseudoQueue class will implement our standard queue interface (the two methods listed below), but will internally only utilize 2 Stack objects. Ensure that you create your class with the following methods:

  2. enqueue(value) which inserts value into the PseudoQueue, using a first-in, first-out approach.

  3. dequeue() which extracts a value from the PseudoQueue, using a first-in, first-out approach.

Whiteboard Process

WhiteBoard

Approach & Efficiency

For the two methods we write them as simple as possible so we can keep the complextiy as samll as possible.

  1. Enqueue
    • Space: O(1)
    • Time: O(1)
  2. Dequeue
    • Space: O(n)
    • Time: O(n)