Trying to compare a recursive and an iterative algorithm

后端 未结 2 1059
陌清茗
陌清茗 2021-01-26 23:35

I have two algorithms that solve this problem: Generate all sequences of bits within Hamming distance t. Now I want to compare them theoretically (I do have time measurements, i

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 00:11

    The recursive algorithm is O((n choose t) * n) too, by an analysis that charges to each printed combination the cost of the entire call stack at the time that it is printed. We can do this because every invocation of magic (except the two O(1) leaf calls where i < 0, which we could easily do away with) prints something.

    This bound is best possible if you assign printing its true cost. Otherwise, I'm pretty sure that both analyses can be tightened to O(n choose t) excluding printing for t > 0, with details in Knuth 4A.

提交回复
热议问题