A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Counting Complexity and the Sharp-P Class

Graduate Depth 107 in the knowledge graph I know this Set as goal
761prerequisites beneath it
See this on the map →
NP-Completeness and the Cook-Levin TheoremAlternating Turing Machines and the Polynomial Hierarchy
counting-complexity sharp-p #sat counting-problems

Core Idea

#P (sharp-P) is the class of counting problems: given a verifier for an NP problem, count how many accepting paths exist. Computing the exact count is at least as hard as deciding membership. #P-complete problems include counting satisfying assignments, perfect matchings, and Hamiltonian cycles—most of which have no known polynomial-time algorithms.

How It's Best Learned

Study the contrast between decision (SAT ∈ NP) and counting (#SAT ∈ #P). Show that counting perfect matchings is #P-complete even though perfect matching decision is in P.

Common Misconceptions

Explainer

You already know that NP captures decision problems — questions with yes/no answers where a "yes" witness can be verified quickly. SAT asks: is there *any* satisfying assignment to a Boolean formula? The corresponding counting problem, #SAT, asks: *how many* satisfying assignments are there? This shift from existence to enumeration defines the class #P (pronounced "sharp-P"). Where NP problems accept nondeterministic paths that "guess" a solution, a #P problem counts the total number of accepting nondeterministic paths.

The surprising depth of #P emerges from problems where deciding is easy but counting is hard. Consider perfect matchings in a bipartite graph: you can decide whether one exists in polynomial time using standard matching algorithms. But counting the *number* of perfect matchings — computing the permanent of the adjacency matrix — is #P-complete. Valiant proved this in 1979. The permanent looks almost identical to the determinant formula (replace all minus signs with plus signs), yet computing the determinant is in P while computing the permanent is #P-hard. This shows that #P-hardness is not a failure of algorithmic ingenuity but a structural property of the problem.

The relationship between #P and the classes you know from the polynomial hierarchy is indirect but important. #P sits "above" NP in hardness: any #P function is at least as hard as any NP decision problem. Formally, Toda's theorem (1991) shows that the entire polynomial hierarchy PH reduces to P^#P — a single query to a #P oracle can simulate any finite number of alternations between ∃ and ∀ quantifiers. This means counting solutions is strictly more powerful than deciding them, even with the full power of alternation.

Practical consequences are real. Bayesian inference in many graphical models reduces to computing a marginal probability — which amounts to counting weighted solutions. Monte Carlo approximations and FPRAS (fully polynomial randomized approximation schemes) are often the best known alternatives. For #P-complete problems, getting an exact answer is believed to be intractable, but approximate counting is sometimes feasible in polynomial time for problems where exact counting is hard. Understanding #P is therefore not just theoretical: it explains why exact probabilistic inference is computationally expensive and why approximation algorithms dominate in practice.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsLogic Gates FundamentalsImplementing Boolean Functions with GatesKarnaugh Map SimplificationCombinational Circuit DesignFlip-Flops and LatchesFinite State Machines (FSMs)Deterministic Finite Automata (DFA)Nondeterministic Finite Automata (NFA)Two-Way Finite AutomataNFA to DFA Conversion (Subset Construction)DFA Properties and Minimization AlgorithmsRegular Languages: Definition and CharacterizationContext-Free Grammars (CFGs)Pushdown Automata (PDA)Equivalence of CFGs and Pushdown AutomataClosure Properties of Context-Free LanguagesLimitations of Context-Free LanguagesPumping Lemma for Context-Free LanguagesTuring MachinesVariants of Turing Machines and EquivalenceNondeterministic Time Complexity and NPThe P vs. NP ProblemComplexity Class P: Polynomial TimeComplexity Class NP: Nondeterministic Polynomial TimeNP-Completeness and Cook-Levin TheoremThe Cook-Levin TheoremBoolean Satisfiability, Cook-Levin, and ReductionsPolynomial Many-One ReductionsBPP: Bounded Error Probabilistic Polynomial TimeRP and coRP Complexity ClassesPSPACE Complexity ClassThe Polynomial HierarchyPSPACE and PSPACE-CompletenessAlternating Turing Machines and the Polynomial HierarchyCounting Complexity and the Sharp-P Class

Longest path: 108 steps · 761 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.