CSC325 · 2081 · 5 marks
Write short notes on: a) Big Oh, Big Omega, Big theta b) Class P, Class NP and NP-Complete
Write short notes on: a) Big Oh, Big Omega, Big theta b) Class P, Class NP and NP-Complete [5]
Quick answer
Big Oh notation gives the asymptotic upper bound of a function.
Short Notes: Asymptotic Notations and Complexity Classes
a) Big Oh, Big Omega, and Big Theta
Big Oh O(g(n)) - Asymptotic Upper Bound
Definition: A function f(x) is said to be O(g(x)) if and only if there exist two positive constants c and x₀ such that:
For all x >= x₀ : f(x) <= c * g(x)
This means g(n) is the upper bound of f(n). The algorithm will never take more time than this bound.
Example: If f(n) = 3n² + 4n + 1, then:
- 3n² + 4n + 1 <= 14n² for all n >= 1
- Therefore, f(n) = O(n²) with c = 14, x₀ = 1
Big Omega Ω(g(n)) - Asymptotic Lower Bound
Big Omega notation gives the asymptotic lower bound of a function.
Definition: A function f(x) is said to be Ω(g(x)) if and only if there exist two positive constants c and x₀ such that:
For all x >= x₀ : f(x) >= c * g(x)
This means g(n) is the lower bound of f(n).
Example: If f(n) = 3n² + 4n + 1, then:
- 3n² + 4n + 1 >= 3n² for all n >= 1
- Therefore, f(n) = Ω(n²) with c = 3, x₀ = 1
Big Theta Θ(g(n)) - Asymptotic Tight Bound
Big Theta notation gives the asymptotically tight bound of a function.
Definition: A function f(x) is said to be Θ(g(x)) if and only if there exist three positive constants c₁, c₂ and x₀ such that:
For all x >= x₀ : c₁ * g(x) <= f(x) <= c₂ * g(x)
This means g(n) is both an upper and lower bound of f(n).
Example: If f(n) = 3n² + 4n + 1, g(n) = n², choose c₁ = 1, c₂ = 14, n₀ = 1:
- 1 * n² <= 3n² + 4n + 1 <= 14 * n² for all n >= 1
- Therefore, f(n) = Θ(n²)
b) Class P, Class NP, and NP-Complete
Class P (Polynomial Time)
- Class P is the set of all decision problems that can be solved by a deterministic algorithm in polynomial time O(n^k) for some constant k.
- These are considered tractable (efficiently solvable) problems.
- Examples: Sorting, searching, shortest path (Dijkstra's), GCD computation.
Class NP (Non-deterministic Polynomial Time)
- Class NP is the set of all decision problems for which a given solution (certificate) can be verified in polynomial time by a deterministic algorithm.
- NP does not necessarily mean the problem cannot be solved in polynomial time; it means verification is polynomial.
- Every problem in P is also in NP (P ⊆ NP), but whether P = NP is an unsolved problem in computer science.
- Examples: Boolean satisfiability (SAT), Hamiltonian cycle, Subset sum.
NP-Complete
-
A problem X is NP-Complete if:
- X belongs to NP (its solution can be verified in polynomial time), AND
- Every other problem in NP can be reduced to X in polynomial time (X is NP-Hard).
-
NP-Complete problems are the hardest problems in NP.
-
If any NP-Complete problem can be solved in polynomial time, then all NP problems can be solved in polynomial time (i.e., P = NP).
-
Examples: SAT problem, Travelling Salesman Problem (TSP), Knapsack problem, Graph Coloring.
Relationship Summary
P ⊆ NP
NP-Complete ⊆ NP
If P = NP, then all NP-Complete problems become P
| Class | Solvable in Poly Time? | Verifiable in Poly Time? |
|---|---|---|
| P | Yes | Yes |
| NP | Unknown (maybe) | Yes |
| NP-Complete | Unknown | Yes |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.