Skip to main content
  1. Notes/

Pseudo-polynomial algorithms

Equality of numbers

  • O(n)O(n) in both binary and unary coding

Primality test

  • is nn divisible by 2,3,,n2, 3, \dots, \sqrt{n}
  • sub-linear complexity with unary coding of nn
  • exponential complexity with binary coding of nn

Subset sum

  • INPUT: a set SS of nn numbers, number HH
  • GOAL: subset of numbers from SS such that their sum is equal to HH
  • ALGORITHM: test every subset, O(2n)O(2^n)
  • input (1, 1, 1, 1, 1, 1, 1, 1) vs (282^8)
    • (1, 1, 1, 1, 1, 1, 1, 1) -> #1#1#1#1#1#1#1#1
    • (282^8) -> 11111111
  • the same length of the input, but different complexity!

We want to better characterize the input:

  • define an integer problem
  • characterize the input by length of the input (binary) x|x| + maximal number in the input Max(x)Max(x)

Algorithm is pseudo-polynomial if TimeA(x)p(x,Max(x))Time_A(x) \leq p(|x|, Max(x)) for every xUx \in \mathcal{U}

Knapsack problem

  • O(nH)O(nH)
    • nn - number of items
    • HH - sum over all hih_i

There exist a strong NP-hard problems that cannot be solved by pseudo-polynomial algorithm, e.g. TSP.