Introduction to Data Structure and Algorithm
Data Structure and Algorithm consists of two words Data Structure and Algorithm. Now divide the definition into two parts let’s discuss:
What is Data Structure?
Data Structure is a way of organizing, storing, and arranging data in a computer so that we can access, modify or change, and update data easily or efficiently. Data structure is important because we can easily access or change or update data efficiently and quickly.
Data Structure is commonly used in every programming language in which we need to store data for example in machine learning when we train a model we need a data set we first arrange data in just like the manner machines understand and process efficiently.
Different types of data structure are used in a programming language if you understand this you will be able to learn easily store, manage, retrieve and update easily:
Example of Data Structure
We have data of 100+ students that’s consists of students roll number, Marks, Subjects etc
Now we choose a data structure that we can easily store this data for example we chose an Array to store these data an array store data marks of students their roll numbers and subjcts etc.
Types of Data structure
Linear Data Structure:
In linear Data Structure data stored in sequence or sequentially which mean data is stored one after the other. Each Elements of data connect with its previous and next elements. Linear data structure uses consecutive memory locations to store data sequentially. Linear Data structure is called because it store data in a sequence or line
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| Elements | 34 | 55 | 23 | 56 | 78 | 90 | 12 |
For example, Array, Queue Stack.
There are two types of linear data structure
1) Static
2) Dynamic
Now discuess Static data structure in Linear data structure:
Static mean stuck or reserved. In thia data structure data has fixd memory size which mean when we allocate memory size for data it cannot be increased or decreased for example in array when we define the length of array it cannot be changed during the program execution
| int numbers[5]; // Declaring an array of fixed size 5numbers[0] = 10;numbers[1] = 20;numbers[2] = 30;numbers[3] = 40;numbers[4] = 50;numbers[5] = 60; // Error! Array size is fixed to 5 |
Dynamic Data Structure:
In dynamic data Structure the size of memory is not fixed. Memory size can be increased or decreased depending on program requirements Stacks, Queue and linked list are example or Dynamic data structure.
Array: Array is a type of linear data structure that is used to store same data type in sequence or consecutive memory location. All data item stored in same data type for example integer float or character. Each elements has unique index and index must be start with 0.
For example
| // Declare and Initialize Array int numbers[5] = {10, 20, 30, 40, 50}; |
Queue:
Queue is a type of linear data structure that follow the principal of FIFO(First-in-first-out). In queue data added in end of queue and removed from front of the queue. Example:
| Front → [ 10, 20, 30 ] ← Rear ↓ Dequeue (Remove) |
Stack:
Stack is type of linear data structure that follows LIFO (Last-in-first-out) principal. In stack last element added to the stack and first to be memoved.
Example:
| Top ↓ [ 30 ] ← Last In, First Out (LIFO) [ 20 ] [ 10 ] ← Bottom (First In, Last Out) |
Linked list:
In linked list data is linked with pointers. Each element in linked list is called node each node consists of two parts Data and Pointer.
Example:
| [ 10 | *-] → [ 20 | *-] → [ 30 | null ] |
The first node stores 10 and points to the next node.
The second node stores 20 and points to the third node.
The third node stores 30 and points to null (end of the list).
Non Linear Data Structure:
In non linear Data structure data are not stored in sequentially or in a sequence that’s way its called non linear data structure. In non linear data structure data stored in hierarchical manner for example parent and child or in the form of tree or graph. Data is not stored in consecutive memory location.
Tree 
Tree is a type of non linear data structure. Each element store in tree shape. Each element is called node the top node is called root and other node are called child nodes or leaf nodes. Differents types of trees are include like binary tree
Example:
| A ← Root / \ B C / \ \ D E F ← Leaf Nodes |
- A is the Root node.
- B and C are children of A.
- D, E, and F are Leaf nodes (no children).
Graph:
Graph is a non linear data structure in which elements are stored in vertices or nodes or set of edges. A graph consists of two parts:
A Graph consists of:
- Vertices (Nodes): Points where data is stored.
- Edges: Lines that connect the vertices, showing relationships.
| (A) —— (B) | / | | / | | / | (C) —— (D) |
- A, B, C, and D are vertices (nodes).
- Edges show connections (friendships).
- This is an Undirected Graph because connections go both ways
Hope so you understand data structure and its types. Now we discuss about Algorithm:
What is Algorithm:
In simple words we said a step by step procedure to solve a problem is called algorithm. Algorithm is Break down the large problem into smaller step and then solve it. Through algorithm to understand the problem and find solutio easily.
Example:
Algorithm to Make Tea:
- Boil water.
- Add tea leaves or tea bag.
- Add sugar (optional).
- Pour hot water over the tea.
- Let it steep for a few minutes.
- Remove tea leaves or tea bag.
- Pour into a cup and enjoy your tea.
Different types of algorithm are available in data structure:
Searching Algorithms
- Linear Search
- Binary Search
Sorting Algorithms
- Bubble Sort
- Selection Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Heap Sort
- Radix Sort
Recursion Algorithms
Dynamic Programming Algorithms
- Fibonacci Series
- Knapsack Problem
- Longest Common Subsequence
- Matrix Chain Multiplication
Divide and Conquer Algorithms
- Merge Sort
- Quick Sort
- Binary Search
Greedy Algorithms
- Coin Change Problem
- Activity Selection Problem
- Huffman Coding
Backtracking Algorithms
- N-Queens Problem
- Sudoku Solver
- Subset Sum Problem
Combine Defination of DSA
Now we combine the defination of data structure and algorithm:
Data Structure is a way to organize and store data efficiently, while an Algorithm is a step-by-step procedure to solve a problem or perform a task.
By combining we said it is helpful for store manage and process data easily and efficiently to solve complex or difficult problems in programming.