Data Structures & Algorithms
DSA Part-1
- Introduction to Data Structures
- Asymptotic Notations: Big-O, Omega, and Theta Notations
- Time Complexity and Space Complexity Analysis of Algorithms
- 1D Arrays: Memory Representation and Address Calculation
- 2D Arrays: Row-Major and Column-Major Order Formulas and Numericals
- Array Operations: Traversal, Insertion, and Deletion with Algorithms
- Sparse Matrix: Triplet Representation and Linked Representation
- String Operations, Memory Storage, and Pattern Matching Basics
- Linear Search Algorithm and Complexity Analysis
- Binary Search Algorithm (Iterative and Recursive)
- Bubble Sort Algorithm and Optimization
- Selection Sort Algorithm and Step-by-Step Trace
- Insertion Sort Algorithm and In-Place Analysis
- Merge Sort Algorithm (Divide and Conquer Approach)
- Quick Sort Algorithm and Partitioning Methods
- Counting Sort Algorithm (Non-Comparison Sorting)
- Radix Sort Algorithm and Bucket Distribution
DSA Part-2
- Singly Linked List: Concept and Memory Allocation
- Singly Linked List: Insertion Operations
- Singly Linked List: Deletion Operations
- Singly Linked List: Reversal and Search Operations
- Doubly Linked List: Node Structure and Traversal
- Doubly Linked List: Insertion and Deletion Operations
- Circular Singly Linked List: Concept and Operations
- Circular Doubly Linked List: Concept and Operations
- Header Linked List: Grounded and Circular Header Lists
- Polynomial Representation and Addition using Linked List
DSA Part-3
- Stack Data Structure: Array Implementation
- Stack Implementation using Linked List
- Infix, Prefix, and Postfix Notations
- Infix to Postfix Conversion using Stack
- Infix to Prefix Conversion using Stack
- Evaluation of Postfix Expression using Stack
- Recursion and System Stack (Tower of Hanoi)
- Linear Queue: Array Implementation and Operations
- Drawbacks of Linear Queue and Memory Wastage
- Circular Queue: Array Implementation and Condition Checks
- Queue Implementation using Linked List
- Double-Ended Queue (Deque): Input and Output-Restricted
- Priority Queue: Concept, Array and Heap Representation
DSA Part-4
- Tree Data Structure: Terminology and Basic Concepts
- Binary Trees: Types and Properties
- Binary Tree Traversals: Inorder, Preorder, and Postorder
- Level Order Traversal of Binary Tree
- Binary Search Tree (BST): Concept and Search Operation
- Binary Search Tree (BST): Insertion and Deletion Operations
- AVL Tree: Concept and Balance Factor
- AVL Tree Rotations: LL, RR, LR, and RL Rotations
- Binary Heap: Min-Heap and Max-Heap Properties
- Heap Operations: Heapify, Insertion, and Deletion
- B-Tree: Properties, Structure, and Insertion
- B+ Tree: Structure and Comparison with B-Tree
DSA Part-5
- Graph Data Structure: Terminology and Types
- Graph Representation: Adjacency Matrix and Adjacency List
- Breadth First Search (BFS) Algorithm for Graphs
- Depth First Search (DFS) Algorithm for Graphs
- Hashing: Hash Tables and Hash Functions
- Collision Resolution: Open Addressing Techniques
- Collision Resolution: Separate Chaining Method
Binary Search Algorithm (Iterative and Recursive)
Binary Search ek highly efficient searching algorithm hai jo Divide and Conquer paradigm par kaam karta hai. Binary search ki primary prerequisite yeh hai ki array pehle se sorted hona chahiye (ascending ya descending order me).
Binary search har step me search space ko aada (half) kar deta hai, jisse iski running time logarithmic ho jaati hai.
Working Mechanism
Search range ko maintain karne ke liye do pointers use hote hain: low = 0 aur high = n - 1. Har iteration me middle index calculate kiya jata hai:
mid = low + (high - low) / 2; // Integer overflow avoid karne ke liye
- Agar
A[mid] == Key: Search successful, indexmidreturn karte hain. - Agar
Key < A[mid]: Target element left half me hoga, isliyehigh = mid - 1set karte hain. - Agar
Key > A[mid]: Target element right half me hoga, isliyelow = mid + 1set karte hain.
Sorted Array: [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ]
Index: 0 1 2 3 4 5 6 7 8
Target Key = 70
Pass 1: low=0, high=8 -> mid = (0+8)/2 = 4 (A[4] = 50)
Key(70) > 50 -> Search Right Half: low = mid + 1 = 5
Pass 2: low=5, high=8 -> mid = (5+8)/2 = 6 (A[6] = 70)
Key(70) == 70 -> Match Found at index 6!
Algorithms: Iterative and Recursive
1. Iterative Algorithm
BINARY_SEARCH_ITERATIVE(A, N, KEY)
1. Set low = 0, high = N - 1
2. While low <= high do:
3. mid = low + (high - low) / 2
4. If A[mid] == KEY then:
Return mid
5. Else If KEY < A[mid] then:
high = mid - 1
6. Else:
low = mid + 1
7. End of While
8. Return -1 [Not Found]
2. Recursive Algorithm
BINARY_SEARCH_RECURSIVE(A, low, high, KEY)
1. If low > high then:
Return -1
2. mid = low + (high - low) / 2
3. If A[mid] == KEY then:
Return mid
4. Else If KEY < A[mid] then:
Return BINARY_SEARCH_RECURSIVE(A, low, mid - 1, KEY)
5. Else:
Return BINARY_SEARCH_RECURSIVE(A, mid + 1, high, KEY)
Complexity Comparison
- Best-case Time: O(1) jab element exactly pehle mid par mil jaye.
- Worst-case Time: O(log n) – Har step par input size half ho jata hai:
n, n/2, n/4, ..., 1 => log2(n) steps. - Space Complexity: Iterative version me O(1) auxiliary space, jabki Recursive version me O(log n) recursion call stack memory lagti hai.
Agli post me hum sorting start karenge: Bubble Sort Algorithm and Optimization.