Skip to content

Latest commit

 

History

History
61 lines (36 loc) · 2.15 KB

File metadata and controls

61 lines (36 loc) · 2.15 KB

Stacks and Queues

push / enqueue

  • arguments: new value
  • push: adds a new node with the given value at the top of the stack
  • enqueue: adds a new node with the given value at the end of the queue

pop / dequeue

  • arguments: none
  • pop: removes the node at the top of the stack and returns its value
  • dequeue: removes the node at the front of the queue and returns its value

peek

  • arguments: none
  • returns either the top of the stack's value or the front of the queue's value

is_empty

  • arguments: none
  • checks to see if a stack or queue is empty, returns a boolean

Whiteboard Process

Image of the whiteboard process for Queues

Link to Figma Board of image above for queues

Image of whiteboard process for Stacks

Link to Figma board of image above for stacks

Approach & Efficiency

Stacks: Time: O(1) - because only deals with one node at a time for all of these method, since the node’s being accessed are only on the top Space: O(n) - because it will be the amount of space for each of the nodes in the stack

Queues: Time: O(1) - because only deals with one node at a time for all of these method, since it knows the head and tail of the queue Space: O(n) - because it will be the amount of space for each of the nodes in the queue

Solution

Terminal command: python3 -m pytest

Queue Tests in terminal: collected 12 items, 12 passed in 0.01s

Stacks Tests in terminal: collected 14 items, 14 passed in 0.01s

Code Links

Queue Stack