The Wayback Machine - https://web.archive.org/web/20241121231217/https://www.geeksforgeeks.org/stack-meaning-in-dsa/
Open In App

Stack Definition & Meaning in DSA

Last Updated : 06 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A stack is defined as a linear data structure that is open at one end and the operations follow the Last-In-First-Out (LIFO) order.

Example of Stack

Example of Stack

Characteristics of  Stack:

  • The stack follows the LIFO order, which means that the last element added to the stack will be the first element to be removed.
  • A register that points to the top of the stack is known as the stack pointer. It is used to keep track of the current position of the top of the stack.
  • A stack is also characterized by its capacity, which is the maximum number of elements it can hold at any given time. If an attempt is made to push an element onto a full stack, a stack overflow error will occur.

Applications of Stack:

  •  Mathematical expression: Stacks are used to evaluate mathematical expressions, such as infix, postfix, and prefix expressions. They are also used to convert one expression to another.
  • Backtracking: Stacks are used in backtracking algorithms to keep track of the path taken to reach a particular point in the algorithm.
  • Function call: Stacks are used to keep track of function calls and return addresses in programming languages.
  • Memory Management: Stacks are used in memory management to allocate and deallocate memory for variables and data structures.

To learn more about stack applications. refer to this article.

Advantages of Stack:

  • Stacks are simple to implement and can be created using arrays, linked lists, or even dynamic memory allocation.
  • Stacks are efficient in memory management as they only allocate memory for the elements that are currently in the stack.
  • The push and pop operations have O(1) time complexity, which means that take constant time regardless of the size of the stack.

To learn more about the advantages of the stack, refer to this article.

Disadvantages of Stack:

  • Static stacks have a fixed size, which means that in a stack we can add limited elements.
  • Stacks can suffer from overflow when you try to add more elements than the stack size, and underflow when you try to remove an element from an empty stack.
  • Stacks can only be used to store and retrieve data in a specific order, whereas queues and trees can be used to store and retrieve data in a variety of orders.

To learn more about the disadvantages of the stack, refer to this article.

What else can you read?



Similar Reads

Disjoint Set meaning and definition in DSA
Disjoint Set is a data structure that keeps track of a set of elements partitioned into a number of disjoint subsets and it is used to efficiently solve problems that involve grouping elements into sets and performing operations on them. Characteristics of the Disjoint Set:It keeps a set partitioned into disjoint subsets.It allows the efficient uni
2 min read
Balanced Binary Tree definition & meaning in DSA
Balanced binary tree is defined as a binary tree data structure where there is no more than one height difference between the left and right subtrees of any given node. Mathematically Height of left subtree - Height of right subtree ≤1 Properties of Balanced Binary Tree: A balanced binary tree has a height that is logarithmic in the number of nodes
2 min read
Array Definition & Meaning in DSA
An array is a collection of items of same data type stored at contiguous memory locations Types of Arrays:One-dimensional Array: It is the simplest kind of array where all the elements are stored linearly in a single row. Two-dimensional Array: A two-dimensional array is an array with 2 dimensions, i.e., each unique element is accessed using two it
4 min read
What is Tree | Tree Definition & Meaning in DSA
A tree is defined as a hierarchical data structure in which the elements (known as nodes) are linked together via edges such that there is only one path between any two node of the tree. Properties of Trees:Number of edges: An edge can be defined as the connection between two nodes. If a tree has N nodes then it will have (N-1) edges.Depth of a nod
4 min read
Ternary Search Tree meaning & definition in DSA
Ternary Search Tree is defined as a special trie data structure where the child nodes of a standard trie are ordered as a binary search tree where each node can have at most three children and the left, middle and right subtrees of a node contain values that are less than, equal or greater than the node. Characteristics of Ternary Search Tree:TST i
3 min read
Generic Tree meaning & definition in DSA
A generic tree (or N-ary Tree) is a type of tree data structure where each node can have at most N number of children where N can be any integer. Characteristics of Generic Tree:Each node can have zero or more child nodes.A node can have N number of children where N can be any integer.Each node has a list of pointers that point to the children.Appl
2 min read
Red-Black Tree definition & meaning in DSA
A red-black tree is a self-balancing binary search tree in which each node of the tree has an color, which can either be red or black. Characteristics of Red Black Tree:The root node is always black and each node can be either black or red.Every leaf node of the red-black tree is black.The children of red nodes are black.The number of black nodes w
2 min read
Connected component definition & meaning in DSA
Connected component in an undirected graph refers to a group of vertices that are connected to each other through edges, but not connected to other vertices outside the group. For example in the graph shown below, {0, 1, 2} form a connected component and {3, 4} form another connected component. Characteristics of Connected Component:A connected com
1 min read
Divide and Conquer definition & meaning in DSA
Divide and Conquer is a type of algorithm which involves breaking down a difficult problem into smaller subproblems, solving the subproblems individually and then merging the solutions of those subproblems to solve the actual problem. Properties of Divide and Conquer:Divides the problem into smaller subproblems.Each subproblem is solved independent
2 min read
Graph definition & meaning in DSA
A Graph is a non-linear data structure consisting of vertices and edges where two vertices are connected by an edge. Properties of a Graph:Vertices (nodes): The points where edges meet in a graph are known as vertices or nodes. A vertex can represent a physical object, concept, or abstract entity.Edges: The connections between vertices are known as
4 min read
Singly Linked List definition & meaning DSA
A singly linked list is a special type of linked list in which each node has only one link that points to the next node in the linked list. Characteristics of a Singly Linked List:Each node holds a single value and a reference to the next node in the list.The list has a head, which is a reference to the first node in the list. We can access all ite
1 min read
Adjacency matrix meaning and definition in DSA
An adjacency matrix is a square matrix of N x N size where N is the number of nodes in the graph and it is used to represent the connections between the edges of a graph. Characteristics of the adjacency matrix are:The size of the matrix is determined by the number of vertices (or nodes) in a graph.The edges in the graph are represented as values i
2 min read
What is DSA | DSA Full Form
What is DSA?DSA(Data Structures and Algorithms) is defined as a combination of two separate yet interrelated topics – Data Structure and Algorithms. DSA is one of the most important skills that every computer science student must have. It is often seen that people with good knowledge of these technologies are better programmers than others and thus
2 min read
Circular Linked List meaning in DSA
A circular linked list is a special type of linked list in which the last node is connected to the first node, creating a continuous loop. In a circular linked list, each node has a reference to the next node in the sequence, just like in a regular linked list, but the last node's reference points back to the first node. Characteristics of Circular
3 min read
Queue meaning in DSA
A Queue is defined as a linear data structure that is open at both ends and the operations are performed in the First In First Out (FIFO) order. Characteristics of Queue:The first item added to the queue is the first one to be processed (or can be firstly deleted/removed), and subsequent items are processed in the order they were added.Enqueue and
3 min read
Subarray meaning in DSA
A subarray is a portion of an array that consists of consecutive elements from the original array. Characteristics of a Subarray:Contiguity: The elements in a subarray are contiguous, meaning they are consecutive and in order in the original array.Length: The length of a subarray can be any positive integer, from 1 to the length of the original arr
2 min read
Deque meaning in DSA
Deque, which stands for Double Ended Queue, is a special type of queue that allows adding and removing elements from both front and rear ends. Characteristics: of Deque:Dynamic size: The size of a deque can change dynamically during the execution of a program.Linear: Elements in a deque are stored linearly and can be accessed in a sequential manner
2 min read
Min Heap meaning in DSA
A min heap is a binary tree-based data structure where the value of each node is less than or equal to its child nodes. In other words, the root node is always the minimum element in the heap. Here is an example of the min heap tree: Characteristics of Min Heap :A min heap is a complete binary tree. This property ensures that the tree is balanced a
3 min read
Dynamic Programming meaning in DSA
Dynamic Programming is defined as an algorithmic technique that is used to solve problems by breaking them into smaller subproblems and avoiding repeated calculation of overlapping subproblems and using the property that the solution of the problem depends on the optimal solution of the subproblems Properties of Dynamic Programming:Optimal Substruc
2 min read
Doubly Linked List meaning in DSA
A doubly linked list is a special type of linked list in which each node contains a pointer to the previous node as well as the next node in the structure. Characteristics of the Doubly Linked List: The characteristics of a doubly linked list are as follows: Dynamic size: The size of a doubly linked list can change dynamically, meaning that nodes c
3 min read
Backtracking meaning in DSA
Backtracking can be defined as a general algorithmic technique that considers searching every possible combination in order to solve a computational problem. Backtracking simple structure is shown like the following: Properties of Backtracking:Incremental construction: Backtracking builds a solution incrementally by constructing a partial solution
3 min read
Binary Indexed Tree/Fenwick Tree meaning in DSA
Binary Indexed Tree (BIT), also known as Fenwick Tree, is a data structure used for efficiently querying and updating cumulative frequency tables, or prefix sums. A Fenwick Tree is a complete binary tree, where each node represents a range of elements in an array and stores the sum of the elements in that range. Below is a simple structure of a Bin
3 min read
Branch and Bound meaning in DSA
Branch and bound is an algorithmic technique used in computer science to solve optimization problems. Branch and bound is a systematic way of exploring all possible solutions to a problem by dividing the problem space into smaller sub-problems and then applying bounds or constraints to eliminate certain subproblems from consideration. Characteristi
3 min read
Hashing meaning in DSA
Hashing is defined as a data distribution technique that transforms given key into a different value using hash function for faster access to data. Characteristics of Hashing:Hashing maps the data object to exactly one memory bucket.It allows uniform distribution of keys across the memory.Uses different functions to perform hashing such as mid squa
2 min read
Max Heap meaning in DSA
A max heap is a complete binary tree in which every parent node has a value greater than or equal to its children nodes. Properties of a Max Heap :A max heap is a complete binary tree, meaning that all levels of the tree are completely filled, except possibly the last level which is filled from left to right.In a max heap, every parent node has a v
3 min read
What is Sorting in DSA | Sorting meaning
Sorting is defined as the process of arranging a collection of data elements in a specific order, usually in ascending or descending order based on a specific attribute of the data elements. Characteristics of Sorting:Time Complexity: Time complexity, a measure of how long it takes to run an algorithm, is used to categorize sorting algorithms. The
3 min read
Linked List meaning in DSA
A linked list is a linear data structure used for storing a sequence of elements, where each element is stored in a node that contains both the element and a pointer to the next node in the sequence. Types of linked lists: Linked lists can be classified in the following categories Singly Linked List: This type of linked list consists of nodes that
4 min read
Unstable Sort meaning in DSA
Unstable sorting algorithm can be defined as sorting algorithm in which the order of objects with the same values in the sorted array are not guaranteed to be the same as in the input array. Properties of Unstable Sorting Algorithm:They do not require the overhead of keeping the order of equal elements, these algorithms are quicker than stable sort
2 min read
Substring meaning in DSA
A substring is defined as a contiguous part of a string, i.e., a string inside another string. Characteristics of Substring: Starting position of a substring is greater than or equal to the starting index of the string and the ending position is less than or equal to the final position.The maximum length of a substring can be at most the same as th
2 min read
Subsequence meaning in DSA
A subsequence is defined as a sequence that can be derived from another string/sequence by deleting some or none of the elements without changing the order of the remaining elements. For example: Let's take "GeeksForGeeks", GeeksF will be a subsequence of "GeeksForGeeks". Properties of Subsequence:A sequence is a subsequence of itself.The empty seq
2 min read
Practice Tags :
three90RightbarBannerImg