Time Complexity of Common Algorithms
Algorithm Best Case Average Case Worst Case Notes
Selection Sort O(n²) O(n²) O(n²) Not adaptive; independent of input order
Quick Sort O(n log n) O(n log n) O(n²) Worst case when pivot selection is poor
Fractional Knapsack O(n log n) O(n log n) O(n log n) Sorting items by value/weight ratio
Prim’s Algorithm O(E + V log V) - O(E + V log V) Using Min Heap / priority queue
Longest Common Subsequence (LCS)
O(m × n) O(m × n) O(m × n) m, n = lengths of two sequences
Floyd–Warshall Algorithm O(V³) O(V³) O(V³) All-pairs shortest path algorithm
0/1 Knapsack (DP) O(n × W) O(n × W) O(n × W) W = capacity of knapsack