INTERMEDIATEFrequently Tested 4 min read 18 views
Sorting Bounds, Stability, Inversions & P / NP / NP-Complete Reductions
Decision-tree Omega(n log n) lower bound, stability & in-place comparison table, counting array inversions, and polynomial-time Karp reductions (P, NP, NP-Hard, NP-Complete).
1. Complete Sorting Algorithms Cheat Matrix
| Algorithm | Best | Average | Worst | Aux Space | Stable? |
|---|---|---|---|---|---|
| Insertion Sort | Yes | ||||
| Merge Sort | Yes | ||||
| Heap Sort | (or all equal) | No | |||
| Quick Sort | stack | No | |||
| Counting Sort | Yes |
- Inversions: A pair with . Maximum inversions in elements (reverse sorted). Insertion Sort takes time where is the number of inversions!
2. Complexity Classes: P, NP, NP-Complete & NP-Hard
- : Decision problems solvable by a Deterministic Turing Machine in polynomial time . (Shortest Path, MST, 2-SAT, Eulerian Circuit, Linear Programming).
- : Decision problems whose "YES" certificates can be verified in deterministic polynomial time (equivalently solved by a Non-Deterministic TM in polynomial time). Note: .
- -Hard: At least as hard as every problem in (). Need not even be in (e.g., the Halting Problem is Undecidable AND -Hard!).
- -Complete (): . Classic problems: 3-SAT, Clique, Vertex Cover, Independent Set, Hamiltonian Cycle, Subset Sum, 0/1 Knapsack (Decision), Graph -Coloring ().
Key Formulas Summary
Comparison Sorting Decision-Tree Lower Bound
Note: Applies to EVERY comparison-based sort in the worst & average case
NP-Hardness Polynomial Reduction Direction
Note: Always reduce a KNOWN hard problem A INTO target problem B!
#Sorting#QuickSort#MergeSort#Inversions#NP-Completeness#Reductions
Practice Questions on This Chapter (3)
Q1GATE CS AlgorithmsMCQEASY
+1M • -0.33
Which sorting algorithm performs the minimum number of comparisons () when the input array is already sorted in ascending order?
⚡ Click an option above to verify instantly
Q2UGC NET / GATE AlgoMCQMEDIUM
+2M • -0.67
Suppose problem is known to be NP-Complete, and we want to prove that a new decision problem is also NP-Complete. Which polynomial-time reduction must we construct?
⚡ Click an option above to verify instantly
Q3GATE CS 2025 MSQMSQMEDIUM
+2M • 0 Neg
Assume . Which of the following complexity-theoretic statements are TRUE?
☑️ Multiple Select Question — pick one or more options, then click Check Answer.