DATA STRUCTURES
Data Structures are the systematic way of
storing data so that data can be used
efficiently
DATA STRUCTURE DEFINATION
• A data structure is a specialized format for organizing,
processing, retrieving and storing data.
• There are several basic and advanced types of data
structures, all designed to arrange data to suit a specific
purpose.
• Data structures make it easy for users to access and work
with the data they need in appropriate ways
CHOOSING RIGHT DATA STRUCTURE
• Choosing an ill-suited data structure could result in slow
runtimes or unresponsive code.
• Five factors to consider when picking a data structure
include the following:
1.What kind of information will be stored?
2.How will that information be used?
3.Where should data persist, or be kept, after it is created?
4.What is the best way to organize the data?
5.What aspects of memory and storage reservation
management should be considered?
DATA STRUCTURE CATEGORIES
CATEGORIES
LINEAR NON LINEAR
(ARRAY,STACKS,QUEUES,
LINK LIST) (TREES)
What is Linear Data Structure
In linear data structure, data is arranged in
linear sequence.
Data items can be traversed in a single run.
In linear data structure elements are
accessed or placed in contiguous(together in
sequence) memory location.
STACKS
Defination: It is a linear data structure that performs
insertion and deletion of elements only from ONE END, known
as top of the stack(TOP)
Adding an item to a stack is called pushing. Removing an item
from a stack is called popping.
EXAMPLES OF STACK:
Operations that can be performed
on STACK:
PUSH.
POP.
OPERATIONS ON STACK
• PUSH: The process to insert an element in the stack is
known as push operation
• POP: The process to delete an element from the stack is
known as pop operation
• POINTS TO REMEMBER
• If no element is present in the stack, it is known as “Stack
Empty” or “Stack Underflow”
• If no more space available to insert in the stack, it is
known as “Stack Full” or “stack overflow”
PUSH : It is used to insert items into the stack.
POP: It is used to delete items from stack.
TOP: It represents the current location of data
in stack.
APPLICATIONS OF STACK
• Some of the real-life applications of data structures are discussed below:
• When you visit websites, you will find browser stores the URL of a page in
the stack. After hitting the back button you will see that browser history
will show the most recent URL where you navigated to it.
• When an individual is trying to make changes in a document, the text
editor will store the previous versions in a stack. Hence, when you press the
undo button, the previous version will be restored. This ‘do’ and ‘undo’ of
text editors is done through the data structure.
• The operating system utilizes a stack for keeping track of memory in the
operating systems. After the program is allocated to memory you will see
that the operating system pushes the memory address to the stack.
• By evaluating the arithmetic expressions, you might be able to use a stack
for storing intermediate results or performing necessary calculations in
the right order. Hence, from data structures, you can perform an evaluation
of arithmetic expressions.
• class Stack
• {
• int s[];
• int top;
• int cap;
• Stack(int m)
• {
• cap=m;
• top=-1;
• s=new int[cap];
•
• }
• void push(int x)
• {
• if(top==(cap-1))
• System.out.println("stack is full");
• else
• {
• System.out.println(x+" inserted in the stack memory");
• s[++top]=x;
• }
• }
• void pop()
• {
• if(top==-1)
• System.out.println("stack underflow");
• else
• System.out.println("element removed from stack is"+s[top--]);
• }
• void display()
• {
• System.out.println("elements of stack are");
• for(int i=0;i<=top;i++)
• System.out.println(s[i]);
• }
• void main()
• {
• push(10);
• push(20);
• display();
• }
• }