diff --git a/stacks_queues/stacks_queues.md b/stacks_queues/stacks_queues.md index 86accb2..124685b 100644 --- a/stacks_queues/stacks_queues.md +++ b/stacks_queues/stacks_queues.md @@ -1,33 +1,33 @@ ## Introduction -Stacks and queues are foundational data structures that are useful when adding and removing in particular orders. It's important to be comfortable with these two data structures. +Stacks and queues are foundational data structures that are useful for problems that rely on adding and removing elements in a particular order. It's important to be comfortable with these two data structures. ## Stacks -A **stack** is a data structure that stores objects in which the most recently stored objects are the first ones to be removed, (LIFO: last in, first out). An example to help you remember the mechanics of a stack is to associate it with stacks in real life. With a stack of plates, the plates that are placed on top of a stack will be the first ones that are removed from the top! +A **stack** stores objects such that the most recently added objects are the first ones to be removed (LIFO: last in, first out). An example to help you remember the mechanics of a stack is to associate it with stacks in real life. In a stack of plates, the ones placed on top will be the first ones removed! ![](https://i.imgur.com/qMSmxsa.png) It's important to know the common operations of a stack. The two key stack operations are: -1) pop(): removing an item from the stack in a last in, first out order (LIFO) -2) push(item): adding an item to the stack +1. pop(): removing an item from the stack in last in, first out order (LIFO) +2. push(item): adding an item (to the top of the stack) ## Queues -A **queue** is a data structure that stores objects in which the most stored objects are the first ones to be removed. A helpful acronym associated with queues is FIFO, first in first out. An example to help you remember the mechanics of a queue is to associate it with queues in real life. With a queue of people waiting to get a seat in a restaurant, the first people to get in the queue will be the first people seated at that restaurant. +A **queue** stores objects such that the objects added earliest are the first ones to be removed (FIFO: first in first out). An example to help you remember the mechanics of a queue is to associate it with queues in real life. In a queue of people waiting to get a seat in a restaurant, the first people in line (in the queue) will be the first to get a table. ![](https://i.imgur.com/NKuZd0s.png) It's important to know the common operations associated with a queue. The two important queue operations are: -1) dequeue(): removing an item from the queue in a first in, first out order (FIFO) -2) enqueue(item): adding an item to the queue +1. dequeue(): removing an item from the queue in first in, first out order (FIFO) +2. enqueue(item): adding an item (to the back of the queue) ## Key takeaways -* Stacks are very useful for it's backtracking features. For example, parsing questions tend to use stacks because of the LIFO property. +* Stacks are very useful for their backtracking features. For example, parsing questions tend to use stacks because of their LIFO property. * Stacks can be used to implement recursive solutions iteratively. -* Queues are useful when the ordering of the data matters as it preserves that ordering. For example, they're used for caching. +* Queues are useful when the ordering of the data matters because they preserve the original ordering. For example, queues are used for caching. ## Example problems -* Stacks: +* Stacks: * [Implement a queue with stacks](https://leetcode.com/problems/implement-queue-using-stacks/description/) * Queues: @@ -35,15 +35,14 @@ It's important to know the common operations associated with a queue. The two im ## Resources ### Guides -* [Overview of stacks & queues with applications](https://www.cs.cmu.edu/~adamchik/15-121/lectures/Stacks%20and%20Queues/Stacks%20and%20Queues.html) -* [In depth stacks guide](https://medium.com/basecs/stacks-and-overflows-dbcf7854dc67) -* [In depth queues guide](https://medium.com/basecs/to-queue-or-not-to-queue-2653bcde5b04) +* [Overview of stacks and queues with applications](https://www.cs.cmu.edu/~adamchik/15-121/lectures/Stacks%20and%20Queues/Stacks%20and%20Queues.html) +* [In-depth stacks guide](https://medium.com/basecs/stacks-and-overflows-dbcf7854dc67) +* [In-depth queues guide](https://medium.com/basecs/to-queue-or-not-to-queue-2653bcde5b04) ### Libraries -* [Java queue library](https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html) -* [Java stack library]( +* [Java Queue library](https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html) +* [Java Stack library]( https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html) * [Python queue library]( https://docs.python.org/2/tutorial/datastructures.html#using-lists-as-queues) * [Python stack library](https://docs.python.org/2/tutorial/datastructures.html#using-lists-as-stacks) -