2006年11月25日 星期六

Towers of Hanoi is not in class NP

根據定義Towers of Hanoi(河內塔)不是P問題,


書上也沒把它歸在NP,


今天我有點懷疑,它是不是NP-hard,


如果不是,他是屬於啥問題?


就上網查了一下,


http://www.cs.uidaho.edu/~karenv/cs213/cs213.useful.pages/np.html


發現以下內容:


Contrast with Infeasible Problems

Provably infeasible problems, like the Towers of Hanoi, at not known to be in the class NP.

Consider: how would you solve the Towers of Hanoi with an infinite number of processors? There does not appear to be any way to take advantage of such plenitude.

Any "solution" to Towers of Hanoi would be a sequence of instructions on how to move the disks, which would be exponentially long and so could not be verified in a polynomial number of steps.

Even guessing doesn't help. For example, guessing where each disk goes next would still require an exponential number of guesses to solve the problem. Such an algorithm would require exponential time


由於這篇文章,前半段是在講np問題的,


與Infeasible Problems對比指的就是NP問題,


因此得知Hanoi Towers屬於Infeasible Problems.



另外在網上查NP問題,


有中文網頁把它翻成Non-polynomial time problem,


比較正確應是Nondeterministic Polynomial time,


指的是在non-deterministic Turing machine上能夠在polynomial time解決的問題,


而deterministic Turing machine,指的是由一個state到下一個state只存在唯一的下一個state.


相對的non-deterministic Turing machine的下一個state並不是唯一(包含零個),


因此,P問題指的就是在deterministic Turing machine用polynomial time能解決的問題.


Codewars: The Baum-Sweet sequence

這題列在7 kyu,我覺得有點難度,應該有6 kyu的程度了。 這題有數學題的感覺,我因為害怕TLE,加上我有感冒, 因此是直接問ChatGPT 4o怎麼解決, 沒想到一開始,ChatGPT是提供TLE的方法, 我再問ChatGPT要如何加快, 才給我夠快的方法, 看了ChatG...