100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What Does NP-Complete Mean?

Understand what NP-complete means, how reductions prove it, and how to explain NP-completeness clearly in a technical interview.

hardQ194 of 227 in Data Structures & Algorithms Est. time: 6 minsLast updated:
Open Code Lab
194 / 227

Expected Interview Answer

A problem is NP-complete if it is in NP β€” meaning a proposed solution can be verified in polynomial time β€” and it is NP-hard, meaning every other problem in NP can be reduced to it in polynomial time, making it one of the hardest problems in NP whose complexity is representative of the whole class.

NP-completeness is established by two ingredients: membership in NP (a certificate can be checked quickly) and a polynomial-time reduction from a known NP-complete problem, showing the new problem is at least as hard. Cook and Levin's theorem proved SAT (Boolean satisfiability) is NP-complete from first principles, and every other NP-complete problem β€” like the traveling salesman decision problem, subset sum, and graph coloring β€” is proven complete by reducing SAT or another already-proven NP-complete problem to it. No polynomial-time algorithm is known for any NP-complete problem, and if one were found for any single NP-complete problem, it would imply P = NP and solve every NP-complete problem in polynomial time. In practice, recognizing a problem as NP-complete tells an engineer to stop hunting for an exact polynomial algorithm and instead reach for heuristics, approximation algorithms, or exponential algorithms that are fast enough on realistic input sizes.

  • Flags problems where an efficient exact algorithm is unlikely to exist
  • Redirects engineering effort toward heuristics or approximations
  • Reductions let hardness proofs be reused across problems
  • Central to deciding P vs NP, one of the biggest open questions in computer science

AI Mentor Explanation

Verifying that a proposed batting order actually beats a specific bowling attack in a simulated match is quick β€” you just run the simulation once and check the score, which is the NP part. Finding that winning order from scratch by trying combinations is much harder, akin to NP-hardness, since there is no known shortcut faster than trying many orders. If a selector could show that solving 'find the best order' for this team is at least as hard as solving it for any other cricket team's roster problem via a translation trick, that connects the two problems the way a reduction connects NP-complete problems. Cricket analysts do not search for a perfect polynomial algorithm here; they use heuristics and past data, exactly how engineers treat NP-complete problems in practice.

Step-by-Step Explanation

  1. Step 1

    Confirm membership in NP

    Show a proposed solution (certificate) can be verified correct in polynomial time.

  2. Step 2

    Pick a known NP-complete problem

    Choose an already-proven NP-complete problem, like SAT, 3-SAT, or subset sum, to reduce from.

  3. Step 3

    Build a polynomial-time reduction

    Transform any instance of the known problem into an instance of the new problem, in polynomial time, preserving yes/no answers.

  4. Step 4

    Conclude NP-completeness

    NP membership plus a valid reduction from an NP-complete problem proves the new problem is NP-complete too.

What Interviewer Expects

  • Distinguish NP (fast verification) from NP-hard (at least as hard as every NP problem)
  • Explain that NP-complete = NP intersected with NP-hard
  • Mention Cook-Levin and SAT as the foundational NP-complete problem
  • Note the practical implication: use heuristics/approximation instead of chasing exact polynomial algorithms

Common Mistakes

  • Saying NP stands for β€œnot polynomial” (it stands for nondeterministic polynomial)
  • Confusing NP-hard with NP-complete (NP-hard problems need not be in NP)
  • Claiming NP-complete problems are proven to have no polynomial algorithm (this is unproven β€” it is P vs NP)
  • Forgetting the reduction must run in polynomial time itself

Best Answer (HR Friendly)

β€œNP-complete means a problem is in the hardest group of problems where we can quickly check if a proposed answer is correct, but nobody has ever found a fast way to actually find that answer from scratch. When I recognize a problem is NP-complete, I know not to waste time hunting for a perfect fast algorithm and instead reach for heuristics or approximations that are good enough in practice.”

Code Example

Fast verification vs. brute-force search for Subset Sum (NP-complete)
def verify_subset_sum(nums, subset_indices, target):
    # Verification is polynomial: just sum the given subset.
    total = sum(nums[i] for i in subset_indices)
    return total == target


def brute_force_subset_sum(nums, target):
    # Finding a solution from scratch is exponential: try all subsets.
    n = len(nums)
    for mask in range(1 << n):
        indices = [i for i in range(n) if mask & (1 << i)]
        if verify_subset_sum(nums, indices, target):
            return indices
    return None

# verify_subset_sum runs in O(n): this is the "NP" part.
# brute_force_subset_sum runs in O(2^n): no known polynomial algorithm exists.
# Subset Sum is NP-complete: it is in NP, and every NP problem reduces to it.

Follow-up Questions

  • How does Cook-Levin's theorem prove SAT is NP-complete?
  • What is the difference between NP-hard and NP-complete with a concrete example of each?
  • Why does finding a polynomial algorithm for one NP-complete problem solve them all?
  • How would you approach solving an NP-complete problem in a production system?

MCQ Practice

1. What two properties must a problem have to be NP-complete?

NP-complete = in NP (fast verification) AND NP-hard (every NP problem polynomial-time reduces to it).

2. Which problem was the first proven NP-complete, forming the basis for later reductions?

Cook and Levin proved SAT is NP-complete directly; nearly all other NP-completeness proofs reduce from SAT or a descendant.

3. If a polynomial-time algorithm were discovered for one NP-complete problem, what would follow?

Because every NP problem reduces to any NP-complete problem in polynomial time, solving one fast solves them all, proving P = NP.

Flash Cards

What does NP stand for? β€” Nondeterministic Polynomial time β€” a proposed solution can be verified in polynomial time.

What makes a problem NP-complete? β€” It is in NP, and every problem in NP can be reduced to it in polynomial time.

Which problem is the foundational NP-complete problem? β€” Boolean Satisfiability (SAT), proven by the Cook-Levin theorem.

What is the practical takeaway when a problem is proven NP-complete? β€” Stop searching for an exact polynomial algorithm; use heuristics or approximation algorithms instead.

1 / 4

Continue Learning