GateMCQSCIENTIFIC PREP LAB
PlanSign Up
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

AlgorithmBestAverageWorstAux SpaceStable?
Insertion SortΘ(n)\Theta(n)Θ(n2)\Theta(n^2)Θ(n2)\Theta(n^2)O(1)\mathcal{O}(1)Yes
Merge SortΘ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)Θ(n)\Theta(n)Yes
Heap SortΘ(nlog⁡n)\Theta(n \log n) (or Θ(n)\Theta(n) all equal)Θ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)O(1)\mathcal{O}(1)No
Quick SortΘ(nlog⁡n)\Theta(n \log n)Θ(nlog⁡n)\Theta(n \log n)Θ(n2)\Theta(n^2)O(log⁡n)\mathcal{O}(\log n) stackNo
Counting SortΘ(n+k)\Theta(n + k)Θ(n+k)\Theta(n + k)Θ(n+k)\Theta(n + k)Θ(n+k)\Theta(n + k)Yes
  • Inversions: A pair (i<j)(i < j) with A[i]>A[j]A[i] > A[j]. Maximum inversions in nn elements =(n2)= \binom{n}{2} (reverse sorted). Insertion Sort takes Θ(n+I)\Theta(n + I) time where II is the number of inversions!

2. Complexity Classes: P, NP, NP-Complete & NP-Hard

  • PP: Decision problems solvable by a Deterministic Turing Machine in polynomial time O(nk)\mathcal{O}(n^k). (Shortest Path, MST, 2-SAT, Eulerian Circuit, Linear Programming).
  • NPNP: Decision problems whose "YES" certificates can be verified in deterministic polynomial time (equivalently solved by a Non-Deterministic TM in polynomial time). Note: P⊆NPP \subseteq NP.
  • NPNP-Hard: At least as hard as every problem in NPNP (∀X∈NP,  X≤pH\forall X \in NP,\; X \le_p H). Need not even be in NPNP (e.g., the Halting Problem is Undecidable AND NPNP-Hard!).
  • NPNP-Complete (NPCNPC): L∈NP  ∧  L∈NP-HardL \in NP \;\land\; L \in NP\text{-Hard}. Classic NPCNPC problems: 3-SAT, Clique, Vertex Cover, Independent Set, Hamiltonian Cycle, Subset Sum, 0/1 Knapsack (Decision), Graph kk-Coloring (k≥3k \ge 3).
Key Formulas Summary
Comparison Sorting Decision-Tree Lower Bound
2h≥n!  ⟹  h≥log⁡2(n!)=Ω(nlog⁡n)2^h \ge n! \implies h \ge \log_2(n!) = \Omega(n \log n)
Note: Applies to EVERY comparison-based sort in the worst & average case
NP-Hardness Polynomial Reduction Direction
A≤pB  ∧  A∈NP-Hard  ⟹  B∈NP-HardA \le_p B \;\land\; A \in \text{NP-Hard} \implies B \in \text{NP-Hard}
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 (Θ(n)\Theta(n)) 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 AA is known to be NP-Complete, and we want to prove that a new decision problem B∈NPB \in \text{NP} 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 P≠NP\mathbf{P \neq NP}. Which of the following complexity-theoretic statements are TRUE?

☑️ Multiple Select Question — pick one or more options, then click Check Answer.
Previous TopicDynamic Programming Masterclass: 0/1 Knapsack, LCS & Matrix Chain MultiplicationNext Topic Famous Sorting Algorithms (Animated): Bubble, Selection, Insertion, Merge, Quick & Heap Sort
Sorting Bounds, Stability, Inversions & P / NP / NP-Complete Reductions — GATE CS Algorithms | GateMCQ