CS 411 Fall 2025 > Outline for November 24, 2025
CS 411 Fall 2025
Outline
for November 24, 2025
Outline
P, NP, NP-Complete (cont’d) [L 11.3]
- \(\mathrm{NP}\)-Completeness
- Good candidates for problems that lie in \(\mathrm{NP}\) but not in \(\mathrm{P}\) would be the hardest problems in \(\mathrm{NP}\); such problems are \(\mathrm{NP}\)-complete. But what does “hard” mean?
- Decision problem \(A\) is polynomially reducible
to decision problem \(B\) if we can write a solution
for problem \(A\) as follows:
[C++]
bool solveA(AInstance x) { BInstance y = f(x); bool result = solveB(y); return result; }where function
fruns in polynomial time. - If \(A\) is polynomially reducible to \(B\), then we think: \(B\) is at least as hard as \(A\).
- A decision problem \(\Pi\) is \(\mathrm{NP}\)-complete
if
- \(\Pi\) lies in \(\mathrm{NP}\).
- Every problem in \(\mathrm{NP}\) is polynomially reducible to \(\Pi\).
- Examples of \(\mathrm{NP}\)-complete problems:
- TSP
- Knapsack
- Decidability
- A decision problem that can be solved by an algorithm is said to be decidable. There are problems that are not decidable.
- The Halting Problem: given a computer program and input for the program, does the program ever halt (terminate, finish) when executed with that input?
- The Halting Problem is not decidable.
We can prove this by contradiction.
Suppose for a contradiction that we have a solution to the Halting Problem.
[C++]
bool halts(string prog, string input);
Now write the following function.
[C++]
void foo(string s) { if (halts(s, s)) while (true) {} // Loop forever }Now suppose
foosourceis a string holding the source code for functionfoo. What does the following do?[C++]
foo(foosource);
Answer: It asks function
haltswhatfoo(foosource)does, and then it does something different. Ifhaltssays it halts, then it hangs, while ifhaltssays it hangs, then it halts. This is impossible. By contradiction, the Halting Problem is not decidable.
Numerical Algorithms [L 11.4]
- Introduction
- Numerical methods are those that deal with numbers, generally fractional values represented to a limited precision, e.g., with floating-point types.
- We contrast numerical approximations with exact methods.
- Numerical methods are heavily used in scientific modeling.
- Error
- In a numerical context, error is the deviation of a computed result from the actual value.
- Error is always present; it does not mean there is a mistake.
- Kinds of error
- Truncation error comes from approximating an infinite computation by a finite one.
- Round-off error comes from representing a real number with a floating-point value or other limited-precision value.
- An important source of error is the loss of precision due to subtractive cancellation: subtracting two large values that are close together gives a small value with a high relative error.
- Measuring error.
Say \(v\) is the actual value,
and \(a\) is a numerical approximation.
- Absolute error: \(|a-v|\).
- Relative error: \(\frac{|a-v|}{v}\approx\frac{|a-v|}{a}\).
- Instability
- Instability in a numerical algorithm is when small changes in the input can result in large changes to the computed results.
- An ill-conditioned problem is one in which such magnification of error is inherent, so that no stable algorithm can be devised.