INTERMEDIATE🔥 High-Yield Exam Topic 4 min read 3 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 ().
📐 Quick Revision Formula Sheet
Comparison Sorting Decision-Tree Lower Bound
💡 Applies to EVERY comparison-based sort in the worst & average case
NP-Hardness Polynomial Reduction Direction
💡 Always reduce a KNOWN hard problem A INTO target problem B!
#Sorting#QuickSort#MergeSort#Inversions#NP-Completeness#Reductions
🎯 Practice PYQs on This Topic (2)
Q1.GATE CS AlgorithmsMCQEASY
+1 Marks • -0.33 NegWhich sorting algorithm performs the minimum number of comparisons () when the input array is already sorted in ascending order?
Q2.UGC NET / GATE AlgoMCQMEDIUM
+2 Marks • -0.67 NegSuppose 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?