Sorting and Searching Algorithms
Dheemanth M D >> Sorting and Searching AlgorithmsThis section focuses on the fundamentals of sorting and searching techniques with explanations and links to practice problems.

Sorting Algorithms:
- Bubble Sort
- Description: Repeatedly swaps adjacent elements if they are in the wrong order.
- Time Complexity: O(n²)
- Practice Problems:
- Sort an array of 0s, 1s, and 2s.
- Merge Sort
- Description: Divides the array into halves, sorts each half, and merges them.
- Time Complexity: O(n log n)
- Practice Problems:
- Count inversions in an array.
- Quick Sort
- Description: Select a pivot and partition the array around it.
- Time Complexity: O(n log n) (average case)
- Practice Problems:
- Find the kth smallest/largest element in an array.
- Heap Sort
- Description: Uses a binary heap to sort elements.
- Time Complexity: O(n log n)
- Practice Problems:
- Sort an array using heap operations.
Searching Algorithms:
- Linear Search
- Description: Traverses each element sequentially.
- Time Complexity: O(n)
- Practice Problems:
- Find the first occurrence of an element in an array.
- Binary Search
- Description: Repeatedly divides the search interval in half.
- Time Complexity: O(log n)
- Practice Problems:
- Search an element in a rotated sorted array.
- Depth First Search (DFS) and Breadth First Search (BFS)
- Description: DFS explores as deep as possible; BFS explores level by level.
- Time Complexity: O(V + E) (for graphs)
- Practice Problems:
- Find connected components in a graph.
- Detect cycles in a directed graph.
Advanced Searching Techniques:
- Ternary Search
- Description: Divides the array into three parts for optimization problems.
- Practice Problems:
- Find the maximum/minimum of a unimodal function.
- Jump Search
- Description: Jumps ahead by fixed steps and performs a linear search within a block.
- Time Complexity: O(√n)
- Practice Problems:
- Find a specific element in a large sorted array.
- Exponential Search
- Description: Useful for unbounded or infinite arrays.
- Practice Problems:
- Search an element in an infinite sorted array.