簡體   English   中英

證明圖靈機計入O(n)?

[英]Proving a Turing Machine counts in O(n)?

因此,在過去的幾天里,我一直在設計Turing Machine,發現在實現過程中,我對二進制文件的計數大約為4n,其中n是我要計數的數字。 所以O(4n)-> O(n) 我不太擅長證明復雜性,但是從研究中我了解到,如果您有圖靈機M,則{0,1} *中的每n個,t_ {M}(n)將持續多長時間需要數到n,對嗎? 然后,如果不停止,則它的最高界限是無窮大。 有沒有辦法在這兩者之間架起橋梁,得出結論,有n個台階確實是最壞的情況? 我永遠不知道從哪里開始打樣,有什么想法嗎?

更新:

以下是我的圖靈機表示形式,用於二進制計數:

import java.util.Scanner;
public class TuringMachine {

/**
 * Divide a number n by 2 shifting right (shift-right-logical) 
 * to figure out the minimum number of bits needed to represent
 * the number in binary.
 */
private static int getNumBits(int n) {
    int c = 0;
    while (n > 0) {
        c++;
        n = n >> 1;
    }
    return c;
}

private static void computeBinaryValues(int n) {
    System.out.println();

    int i, c, state;
    char symbol;
    String t;

    System.out.println("Computed binary values for:"); 

    // Compute values of n = 1 to n  
    for (int j = 1; j <= n; j++) {
        t = ""; // temp string
        state = 0; // current state
        symbol = ' '; // current symbol being read
        c = getNumBits(j) + 1; // minimum number of bits needed + 1 for a buffer
        i = c - 1; // indexing starting from end of the string 

        // initialize temp string to contain all ' ' characters
        for (int k = 0; k < c; k++) {
            t += " ";
        }

        // String builder off "empty" t string 
        StringBuilder s = new StringBuilder(t);
        // The actual binary representation of n + end space buffer
        String a = Integer.toBinaryString(j) + " ";

        // Turing Cycle  
        while (!(s.toString()).equals(a)) { // if the binary build is successful, these match.
            if (state == 0) {
                if (symbol == ' ') {
                    state = 1;
                    i--; // left
                } else { // symbols 0 and 1 rewrite themselves && move right 1
                    i++; // right
                } 
            } else if (state == 1) {
                if (symbol == ' ') {
                    s.setCharAt(i, '1');
                    state = 0;
                    i++; // right
                } else if (symbol == '0') {
                    s.setCharAt(i, '1');
                    state = 0;
                    i++; // right
                } else {
                    s.setCharAt(i, '0');
                    i--; // left
                }
            }
            symbol = s.charAt(i); // get symbol to read from
        }
        System.out.println(j + " -> " + s); // print binary string created from machine
    }
}

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("Enter value for n >= 1: ");;
    computeBinaryValues(in.nextInt());
}
}

因此,使用Ishtar的建議進行歸納:

C(0) = a C(1) = b C(2) = c

令k為常數-根據我的代碼實驗得出的假設為4。

c = k + b b = k + a

他說我們必須證明c(i+1) = c(i) + k然后我才解釋了這是什么意思? (我不理解他的歸納理由)

如果我正確地理解了您的問題,那么您正在嘗試確定您的圖靈機是否停止運行,以及是否沒有,最糟糕的時間復雜度是無限的對嗎? 如果這是您的問題,那么不能在兩者之間架起一座橋梁,為什么呢? 因為停止問題(確定程序是否停止的問題)在機器上無法確定,這意味着不存在用於確定是否停止TM的算法(並且永遠不會存在)。

證明您的機器以O(n)運行的一種方法是歸納證明。 (由於我不知道您的機器是什么樣,所以我不能告訴您這是否是您的機器的正確方法。)將c(n)定義為機器計算長度的輸入磁帶所需的步數n (或者您在數什么?)現在嘗試證明:

  1. c(0)= k
  2. c(1)= l
  3. c(2)= m

如果確實以4n步長運行,則m = 4 + ll = 4 + k 現在最難的部分證明

  1. c(i + 1)= c(i)+ 4

然后我們可以根據證明c(0) = kc(i+1) = c(i) + 4得出結論,對於所有n>=0c(n) = 4*n + k 因為c(n) = O(4n) = O(n)所以機器以O(n)運行。

(您還應證明機器始終會終止並給出正確的結果,但這可能超出范圍。)


更新:

因此,您的機器實際上並沒有計算任何東西。 它永遠運行,寫入所有二進制數字。 如果Java程序輸入了輸入數字,它將停止機器,機器本身將永遠運行,對嗎?

讓我們將機器成功寫入數字的點定義為:state = 0且在讀取input ='blank'之前。 同意?

c(n)定義為步數,機器需要寫n ,(因此狀態= 0,輸入='空白',並且n的二進制表示形式寫在磁帶上)。 現在,嘗試證明c(0) = kc(1) = lc(2) = m k,l和m的實際值! 例如c(0) = 2c(1) = 8 (我沒有嘗試這些值。)只需逐步跟蹤機器並計數。

真正需要證明的是c(i+1) = c(i) + something 然后,您可以將c(i)求解為封閉形式。 可以這樣想,如果在磁帶上寫了111 (狀態= 0,下一個輸入='空白'),則機器要經過多少步才能寫入1000 (狀態= 0,下一個輸入='空白”):4、5、6、7、8或...?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM