October 27, 2025
Key insight: String analysis problems with finite alphabets and deterministic counting are decidable.
countCs: Counting a Specific Symbolcount_cs function searches for “C” and is a specific case.count_cs is computable and tractable.countNs: Counting Any Symbolcount_ns function searches for the value of n and is a general case.count_ns is computable and tractable.more_cs_than_gs: Symbol Comparisonmore_cs_than_gs function compares the count of “C” and “G” symbols.count_cs and count_ns for clarity and reuse.True if there are more Cs than Gs, else False.has_more_ns_than_ms: General Comparisonhas_more_ns_than_ms function generalizes symbol comparison.n and m.True if there are more n symbols than m symbols.str.count() method scans the string once, it always terminates.count() call scans the string once which is O(n).count_cs: O(n)count_ns: O(n)more_cs_than_gs: O(n)has_more_ns_than_ms: O(n)Take-home message: Not all comquaputational problems are equally difficult; understanding computability helps us recognize solvable problems.
str.count() documentationProofgrammers