DSA Java Array Stack (M 25 & 26)
DSA Java Array Stack (M 25 & 26)
Data Structures deals with the study of how data is organized in the
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Classification of Data
Structures
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Classification of Data
Structures
Queues: insertion made at the back and removal made from the front
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Asymptotic Notations
The efficiency of an algorithm is dependent on amount of time, storage and other resources.
Asymptotic notations are mathematical notations used to describe the running time of an
algorithm.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Asymptotic Notations
complexity)
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Array: Practice Examples
1. Java program to read array of size n and find the frequency of the given
element.
2. Java program to find the array type (even, odd or mixed)
Think about the things you can do with such a pile of plates
If you want the plate at the bottom, you must first remove all the plates on top.
Such an arrangement is called Last In First Out - the last item that is the first
item to go out.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
LIFO Principle of Stack
In programming terms, putting an item on top of the stack is called push and
removing an item is called pop.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Basic Operations of Stack
A stack is an object (an abstract data type - ADT) that allows the following
operations:
•Push: Add an element to the top of a stack
•Pop: Remove an element from the top of a stack
•IsEmpty: Check if the stack is empty
•IsFull: Check if the stack is full
•Peek: Get the value of the top element without removing it
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Working of Stack Data
Structure
The operations work as follows:
1. A pointer called TOP is used to keep track of the top element in
the stack.
2. When initializing the stack, we set its value to -1 so that we can
check if the stack is empty by comparing TOP == -1.
3. On pushing an element, we increase the value of TOP and place the
new element in the position pointed to by TOP.
4. On popping an element, we return the element pointed to by TOP and
reduce its value.
5. Before pushing, we check if the stack is already full
6. Before popping, we check if the stack is already empty
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Working of Stack Data
Structure
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Stack Applications
Applications of Stack Data Structure
Although stack is a simple data structure to implement, it is very powerful.
The most common uses of a stack are:
• To reverse a word - Put all the letters in a stack and pop them out.
Because of the LIFO order of stack, you will get the letters in reverse
order.
• In compilers - Compilers use the stack to calculate the value of
expressions like
2 + 4 / 5 * (7 - 9) by converting the expression to prefix or postfix form.
• In browsers - The back button in a browser saves all the URLs you have
visited previously in a stack. Each time you visit a new page, it is added on
top of the stack. When you press the back button, the current URL is removed
from the stack, and the previous URL is accessed.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video