1.DS Notes Introduction
1.DS Notes Introduction
Data Structures:
A data structure is an arrangement of data in a computer's memory or even disk storage.
Data structures can be classified into two types
Algorithm:
Step by Step process of representing solution to a problem in words is called an Algorithm.
Characteristics of an Algorithm:
Input : An algorithm should have zero or more inputs
Output: An algorithm should have one or more outputs
Finiteness: Every step in an algorithm should end in finite amount of time
Unambiguous: Each step in an algorithm should clearly stated
Effectiveness: Each step in an algorithm should be effective
1
Advanced Data Structures
2
Advanced Data Structures
Stack :
Stack is a Linear Data Structure which follows Last in First Out mechanism.
It means: the first element inserted is the last one to be removed
Stack uses a variable called top which points topmost element in the stack. top is incremented
while pushing (inserting) an element in to the stack and decremented while poping (deleting) an
element from the stack
top
D top
C top C C
B top B B B
A top A A A A
Applications of Stack:
3
Advanced Data Structures
Queue:
Queue is a Linear Data Structure which follows First in First out mechanism.
It means: the first element inserted is the first one to be removed
Queue uses two variables rear and front. Rear is incremented while inserting an element into the
queue and front is incremented while deleting element from the queue
rear
D rear
C rear C D
B rear B C
rear front B
front front front
A front A A A B
Insert(A) Insert(B) Insert(C) Insert(D) Delete()
Note:
While inserting an element into the queue, queue is full condition should be checked
While deleting an element from the queue, queue is empty condition should be checked
Applications of Queues:
Real life examples
Waiting in line
Waiting on hold for tech support
Applications related to Computer Science
Threads
Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
4
Advanced Data Structures
Linked List:
To overcome the disadvantage of fixed size arrays linked list were introduced.
A linked list consists of nodes of data which are connected with each other. Every node consist
of two parts data and the link to other nodes. The nodes are created dynamically.
NODE
bat
Data link