Stack |CONCEPT|

HolySpirit
2 min readDec 3, 2023

--

In this article let’s discuss another important concept in data structure called stacks and queues. In our previous articles, we have discussed several concepts in the linked list. Please do read those articles, it would greatly help you to get the concepts clear we also dealt with some important problems based on the concepts. From the concept of stacks and queues, you will get at least one problem if you are facing any coding interviews. These are the easy concepts that you can grasp easily.

Stack:

The principle of the stack is first in and last out(Last in and first out). Let’s take an example of a pile of plates in which the plate at the top is the one that is inserted at the last and the first to use. The below picture shows a real-time example of a stack.

In terms of data structure, the stack is the linear data structure. It is like a container where you can throw your data and you can take them out but in the same way that you inserted i.e. you can remove data from where you recently inserted the data(the last data that is inserted).

Where the stacks are used in computers?

👊Memory Management

👊Recursion

👊Expression evaluation

👊Expression conversion

👊Undo and Redo in editors

👊History of the browser

Basic operations:

Let’s see some basic operations on a stack that we will do. The operations are push (inserting an element into the stack ), pop(removing an element from the stack), and isEmpty(checking whether the stack is empty or not).

You can implement this data structure as either an array or a linked list.

https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.programiz.com%2Fdsa%2Fstack&psig=AOvVaw11Fz3Fxt2Qs2igiGFJjcCp&ust=1701699868728000&source=images&cd=vfe&opi=89978449&ved=0CBIQjRxqFwoTCOCnwY6884IDFQAAAAAdAAAAABAEF

Points to remember:

If you're working with stacks, be mindful of potential stack overflows. Let’s see where the stack overflow occurs,

Infinite recursion

Deep recursion

Insufficient stack space.

We will get ourselves to understand these concepts by solving some standard leetcode problems in our upcoming articles.

If you find any value in this article, consider FOLLOWING me! Thanks 😇

#LearnInPublic #HappyCoding

--

--

HolySpirit

Budding Programmer sharing insights on life 👨‍💻✨ | Passionate about coding, tech trends, and personal growth | Join me on my journey of learning and discovery