reading_notes

Read: Stacks & Queues

Stacks

In programming, a stack is an abstract, linear data type with a predefined capacity (or boundary). It follows a particular order for adding or removing elements. Linear data structures organize their components in a straight line, so if we we add or remove an element, they will grow or shrink respectively.

methods of the Stack class:


Queues

A queue is a lot like a stack. A Queue is also a linear structure that follows a First In First Out (FIFO) order, but they differ in how elements are removed. Queues are open from both ends: one end for inserting data (enqueue), and the other end for removing data (dequeue).A stack is only open from one end.

Simple difference: For a stack we remove the most recently added element, but for a queue, we remove the “oldest” element.

Pros and Cons of Stack and Queues

Pros

Stacks(Pros) Stacks(Cons)
It is easy to implement and logical for beginners Random access to elements in a stack is nearly impossible
It allows you to control how memory is allocated Neither flexible nor scalable
Easier to use than queues Variables cannot be resized.
Queue(Pros) Queue(Cons)
flexible. Inserting/ removing elements from the middle is complex.
They can handle multiple data types Queues are not readily searchable
Data queues are fast and optimized Classical queues don’t have any space for element priorities

Resources :

  1. https://codefellows.github.io/common_curriculum/data_structures_and_algorithms/Code_401/class-10/resources/stacks_and_queues.html
  2. https://www.educative.io/blog/data-structures-stack-queue-java-tutorial
  3. https://codegym.cc/groups/posts/291-data-structures-stack-and-queue
  4. https://www.quora.com/What-are-the-advantages-and-disadvantages-of-queue-and-stack (only of part of pros and cons)