DATA STRUCTURES
Data Structure:
• Data Structure is a way of organising data in computer memory so that it can be used effectively and
efficiently.
• It helps to reduce the space and time complexities of different tasks.
• Types of Data Structures:
Static DS Array
Linear DS Stack
Data Structure Dynamic DS Queue
(DS)
Tree Linked List
Non Linear DS
Graph
• Linear Data Structures: Elements are arranged in a linear pattern.
• Non-Linear Data Structures: Elements are arranged in hierarchical or non linear pattern.
• Statis DS are those to which memory is allocated only once. It cannot be changed later on.
• Dynamic DS take only that much memory as is required. If more memory is required, it can be allocated at
runtime.
Arrays:
• It is a collection of data items stored in contiguous memory locations.
• Multiple values can be stored under one variable name with different index numbers.
• Each element can be accessed using index number along with array name. e.g in the given image , to access
element 12 we will write Array[3] where 3 is the index number of 12.
Stacks:
• Data elements in stack are placed one on top of another.
• All operations are performed at the top of the stack.
• Operations on stacks:
o PUSH : inserting a new element at the top of the stack.
o POP : removing an element from top of the stack.
• The order of operations is always LIFO(Last In First Out) or FILO (First In Last Out).
Queue:
• Queue is a data structure in which elements are placed in a linear order.
• Each queue has a HEAD and a TAIL.
• An new element is added at the tail and an existing element is removed from the head.
• Operations on queues:
o ENQUEUE: adds an element at the end of the queue.
o DEQUEUE: removes an element from front of the queue.
• The order of operations is FIFO(First In First Out).
Linked List:
• In linked list, the elements are not stored on contiguous memory locations.
• Each element of a linked list is known as NODE.
• A node has 2 parts: data and address to next node.
Tree:
• A tree data structure stores the data in hierarchical format.
Graphs:
• Graph is a non linear data structure.
• It is a collection of nodes that are connected by edges.