📜  计算复杂性与乔姆斯基层次结构

📅  最后修改于: 2022-05-13 01:54:10.575000             🧑  作者: Mango

计算复杂性与乔姆斯基层次结构

1. 计算复杂度:
计算复杂度,衡量特定算法在运行时消耗的计算资源(时间和空间)的数量。

图灵机的时间复杂度由函数T(n) 给出,其中

T(n) = TM 处理长度为 n 的字符串的最大移动次数。

图灵机的空间复杂度由函数S(n) 给出,其中

S(n) = TM 用于长度为 n 的输入的最大带方块数。

简单图灵机时间复杂度
考虑语言,

L = {ωcωR  | ω∈(0+1)*}

要识别 ωcω R形式的字符串,TM 需要:

比较第一个和最后一个字符= 2n + 1 步

比较两端的第二个字符= 2(n -1) + 1 次移动

找到中心字符c = 1 移动

总移动次数 T(n),

= (2n + 1) + (2 (n - 1) +1)+.......(2(n -(n -1)) + 1) + 1
 = 2(1+2+.........+n)+n = 2 X (n)(n+1) / 2 + n = n2 + 2n
= n2+2n 
= O(n2)

时间复杂度可以通过采用双磁带机来降低。

  • 机器将 c 左侧的输入字符串复制到第二个磁带上。
  • 当在输入磁带上找到 c 时,TM 将其第二个磁带头向左移动。
  • 输入磁带头继续向右移动,第二个磁带头向左移动。
  • 两个头下的符号在头移动时进行比较。
  • 如果所有符号都匹配且中心字符为 c,则接受该字符串。

TM 最多进行 n+1 次移动。

T(n) = n+1 = O(n)

TM 的空间复杂度由S(n) = n + 1 [n 字符串长度和一个空白符号] 给出

非确定性时间和空间复杂度:
如果没有选择序列导致机器进行超过 T(n) 次移动,则非确定性 TM 的时间复杂度为 T(n)。如果没有选择序列需要更多的 S(n) 个磁带单元,则空间复杂度为 S(n)。

乔姆斯基层次结构
可以根据产生式规则对语法进行分类。乔姆斯基将语法分为以下类型:

Grammar TypeGrammar Automaton
Type 0 Unrestricted grammarTuring Machine
Type 1Context-sensitive grammarLinear-bounded automaton
Type 2 Context-free grammarPushdown automaton
Type 3 Regular grammarFinite-state automaton

Type-3 或常规语法:
如果语法的所有产生式都具有以下形式,则该语法称为类型 3 或常规语法:-

A ⇢ ε     A ⇢ a
A ⇢ aB    A ⇢ Ba

其中 a ∈ ∑ 和 A, B ∈ V。

由 type-3 语法生成的语言称为常规语言

类型 2 或上下文无关语法:
如果一个文法的所有产生式都具有以下形式 A ⇢ α 其中 A ∈ V 和 α ∈ (V ∪ T)*,则该文法称为类型 2 或上下文无关文法。

V 是一组变量,T 是一组终端。

由类型 2 语法生成的语言称为上下文无关语言

类型 1 或上下文相关语法:
如果一个文法的所有产生式都具有以下形式,则该文法称为 1 型文法或上下文相关文法:α ⇢ β,其中 β 至少与 α 一样长。

0 型或无限制语法:
可以在不受限制的语法中不受任何限制地编写产生式。如果产生 α ⇢ β,则 α 的长度可能大于 β 的长度。

  • 每个文法也是数字 0 型文法。
  • Type 2 语法也是 Type 1 语法。
  • 第三类文法也是第二类文法。

计算复杂性与乔姆斯基层次结构:

Computational Complexity

Chomsky Hierarchy

Computational complexity is a measure of the number of computing resources(time and space) consumed by a particular algorithm while running.Chomsky Hierarchy represents the class of languages that are accepted by the different machines.
Computational complexity is very important in the analysis of algorithms.The Chomsky hierarchy is important in cognitive science because the complexity of a grammar in the hierarchy can be used to evaluate.  
Computational complexity is the unrestricted grammarChomsky hierarchy is context-sensitive grammar
Computational complexity used in Turing AutomatonChomsky hierarchy used in Linear- bounded automaton