Data Structures are the methods we use to store data in our Computer's Memory.
Types of Data Strucutres
Data Strucutres are divided into (2) categories
- Linear Data Strcutres
Data Structures that store data in a sequential manner
Example: Array, Stack, Queue, Linked List, etc.
- Non-Linear Data Structures
Data Structures that store data in a non-sequential manner
Example: Graphs, Trees.
Linear Data Strucutres
- Array
Arrays are the most simplest type of Data Strucutre they are used to store similar Type of data and their
memory allocation is sequential meaning they're stored one after the other and their memory is
allocation is also done one after the other.
- Stack
Stack is a type of linear data structure and it works on the LIFO (Last in First out) principle
Basic operations of Stack are:
- Push():
adds an element on TOP of the stack
- pop():
removes an element from the TOP of the stack
- isEmpty():
checks wether the stack is empty
- peek():
used to display the element on top without removing it
-
Linked List
A linked list consists of NODES. Each node acts like a building block of linked list and each node
consists of an ADDRESS & a VALUE. The first node known as the HEAD of linked list only
contains an address and the last node of the linked list known as TAIL consist of a value and an
address pointing NULL
Types of Linked Lists
- Singly Linked List:
each node only has (1) address and the direction of traversing can only
be unidirectional.
- Doubly Linked List:
each node has (2) addresses & the direction of traversing can be bi-directional.
- Array List
Simply put, dynamic array. Where the size is initially fixed, but as the array grows and requires more space
a new array is created double the size of original array and all the elements of the old array are copied
into the new array