0% found this document useful (0 votes)
52 views

Stack Using Array

A stack follows the LIFO (last in, first out) principle, where the last element added is the first removed. Elements are added to the top of the stack and can only be removed from the top. Common stack operations include push to add an element, pop to remove the top element, peek to view the top element without removing it, and functions to check if the stack is full, empty, or count the elements. These operations have a time complexity of O(1) since stacks provide constant-time addition and removal of elements from the top.

Uploaded by

Vaibhav Mojidra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Stack Using Array

A stack follows the LIFO (last in, first out) principle, where the last element added is the first removed. Elements are added to the top of the stack and can only be removed from the top. Common stack operations include push to add an element, pop to remove the top element, peek to view the top element without removing it, and functions to check if the stack is full, empty, or count the elements. These operations have a time complexity of O(1) since stacks provide constant-time addition and removal of elements from the top.

Uploaded by

Vaibhav Mojidra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

About (Using Arrays)

A stack is a linear data structure that follows the principle of Last In First Out (LIFO).
This means the last element inserted inside the stack is removed first.
1. A Stack is a linear data structure that follows the LIFO (Last-In-First-Out)
principle. Stack has one end, that is It contains only one pointer top pointer
pointing to the topmost element of the stack.
2. Whenever an element is added in the stack, it is added on the top of the stack,
and the element can be deleted only from the stack. In other words, a stack can
be defined as a container in which insertion and deletion can be done from
the one end known as the top of the stack.
3. To add it has one method Push which add it to topmost in stack O(1)
4. To add it has one method Pop which remove the topmost element in stack O(1)
push()
Adding element to top most
Big O: O(1) constant

pop()
Removing element from top
Big O: O(1) constant

peek()
Just to see the topmost element and not removing it
Big O: O(1) constant

isFull()
To check whether the Stack is full or not
Big O: O(1) constant

isEmpty()
To check whether the Stack is empty or not
Big O: O(1) constant

count()
To return the count of the stack
Big O: O(1) constant
References
Programiz.
Geeksforgeeks

You might also like