Sorting Algorithms
Sorting Algorithms
1. Shell Sort
Definition: An in-place comparison-based sorting algorithm that improves insertion sort by
comparing and swapping elements at gaps.
Time Complexity:
o Average: O(n3/2)O(n^{3/2})O(n3/2)
o Worst: O(n2)O(n^2)O(n2)
2. Quick Sort
Definition: A divide-and-conquer algorithm that selects a pivot, partitions the array, and
recursively sorts subarrays.
Time Complexity:
o Worst: O(n2)O(n^2)O(n2)
3. Merge Sort
Definition: A divide-and-conquer algorithm that splits the array, sorts the subarrays, and
merges them back in order.
Time Complexity:
4. Heap Sort
Definition: A comparison-based algorithm that builds a max heap and repeatedly extracts
the largest element.
Time Complexity:
5. Sorting in Linear Time (e.g., Counting Sort, Radix Sort, Bucket Sort)
Definition: Non-comparison-based algorithms that sort based on counting occurrences or
placing elements in buckets.
Time Complexity:
7. B-Trees
Definition: A self-balancing search tree optimized for systems that read and write large
blocks of data.
Time Complexity:
8. Binomial Heaps
Definition: A collection of binomial trees used for efficient priority queue operations.
Time Complexity:
9. Fibonacci Heaps
Definition: A heap data structure that supports operations like decrease-key efficiently.
Time Complexity:
o Insert: O(1)O(1)O(1)
10. Tries
Definition: A tree-like data structure for storing strings, where keys are represented by paths
from the root.
Time Complexity:
o Best: O(1)O(1)O(1)
Greedy Algorithms
Dynamic Programming
Backtracking
Selected Topics
1. Shell Sort
o Definition: A generalized version of insertion sort that first sorts elements far apart
and reduces the gap between them over iterations.
o Approach: Uses a gap sequence to divide the array and repeatedly compares and
sorts elements at these intervals.
o Time Complexity:
▪ Average: O(n3/2)O(n^{3/2})O(n3/2)
▪ Worst: O(n2)O(n^2)O(n2)
2. Quick Sort
o Approach: Recursively sort the two partitions such that elements in the left are
smaller than the pivot and the right are larger.
o Time Complexity:
3. Merge Sort
o Approach: Focuses on merging two sorted subarrays into one sorted array.
o Time Complexity:
4. Heap Sort
o Approach: Build a max heap, then remove the largest element, reheapify, and
repeat.
o Time Complexity:
o Time Complexity:
▪ Best, Average, Worst: O(n)O(n)O(n) (for counting sort and radix sort)
6. Red-Black Trees
o Definition: A self-balancing binary search tree that ensures the tree height is
logarithmic.
o Approach: Maintains balance by coloring nodes red or black and rebalancing after
insertions and deletions.
o Time Complexity:
7. B-Trees
o Definition: A generalization of binary search trees designed for systems that handle
large amounts of data and disk storage.
o Time Complexity:
8. Binomial Heaps
o Definition: A collection of binomial trees supporting mergeable heap operations.
o Time Complexity:
9. Fibonacci Heaps
o Approach: Uses a lazy deletion approach, decreasing the cost of certain operations
like decrease-key.
o Time Complexity:
10. Tries
o Definition: A tree structure used for fast string operations like prefix matching.
o Time Complexity:
o Time Complexity:
o Approach: Divides matrices into smaller submatrices and recursively computes their
products.
o Time Complexity: O(n2.81)O(n^{2.81})O(n2.81)
o Definition: Finds the smallest convex polygon enclosing all given points.
o Approach: Algorithms like Graham's Scan or Jarvis March iteratively add points to
the convex boundary.
Greedy Algorithms
o Definition: Maximizes profit by picking fractional parts of items to fit the knapsack.
o Definition: Finds the minimum spanning tree by growing the tree one vertex at a
time.
o Approach: Starts from a random node and selects the smallest edge connecting the
tree to new vertices.
o Definition: Constructs a minimum spanning tree by adding the smallest edges while
avoiding cycles.
o Definition: Finds the shortest path from a source to all vertices in a weighted graph.
Dynamic Programming
19. Knapsack Problem (0/1)