可计算性:接收 P 中偶数长度单词的 DFA 语言是吗?

发布于 2024-12-21 23:52:30 字数 189 浏览 2 评论 0原文

我已经在这个问题上苦苦挣扎了一段时间,但无法想出任何办法。任何指点将非常感激。

问题是:给定所有仅接收偶数长度单词的 DFA 的语言,证明它是否在 P 中。

我考虑过制作一台图灵机,用 BFS/Dijkstra 算法之类的算法遍历给定的 DFA,以便找到从起始状态到接受状态的所有路径,但不知道如何处理循环?

谢谢!

I've been struggling with this one for a while and am not able to come up with anything. Any pointers would be really appreciated.

The problem is: given the language of all DFAs that receive only words of even-length, prove whether it is in P or not.

I've considered making a turing machine that goes over the given DFA in something like BFS/Dijkstra's algorithm in order to find all the paths from the starting state to the accepting one, but have no idea how to handle loops?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始终不够 2024-12-28 23:52:30

我认为它在 P 中,最坏的是二次。 DFA 的每个状态可以有四个

  1. 未访问的奇偶状态 - 状态 0
  2. 已知可在奇数步中到达 - 状态 1
  3. 已知可在偶数步中到达 - 状态 2
  4. 已知在两者中均可到达,奇数和偶数步数 -- 状态 3

将所有状态标记为未访问,将起始状态放入队列中(FIFO、优先级等),将其奇偶校验状态设置为 2。

child_parity(n)
    switch(n)
        case 0: error 
        case 1: return 2
        case 2: return 1
        case 3: return 3

while(queue not empty)
    dfa_state <- queue
    step_parity = child_parity(dfa_state.parity_state)
    for next_state in dfa_state.children
        old_parity = next_state.parity_state
        next_state.parity_state |= step_parity
        if old_parity != next_state.parity_state // we have learnt something new
            add next_state to queue // remove duplicates if applicable
for as in accept_states
    if as.parity_state & 1 == 1
        return false
return true

除非我忽略了某些内容,否则每个 DFA 状态都会被处理最多两次,每次最多检查 size 个子项是否需要执行操作。

I think it's in P, at worst quadratic. Each state of the DFA can have four parity states

  1. unvisited -- state 0
  2. known to be reachable in an odd number of steps -- state 1
  3. known to be reachable in an even number of steps -- state 2
  4. known to be reachable in both, odd and even numbers of steps -- state 3

Mark all states as unvisited, put the starting state in a queue (FIFO, priority, whatever), set its parity state to 2.

child_parity(n)
    switch(n)
        case 0: error 
        case 1: return 2
        case 2: return 1
        case 3: return 3

while(queue not empty)
    dfa_state <- queue
    step_parity = child_parity(dfa_state.parity_state)
    for next_state in dfa_state.children
        old_parity = next_state.parity_state
        next_state.parity_state |= step_parity
        if old_parity != next_state.parity_state // we have learnt something new
            add next_state to queue // remove duplicates if applicable
for as in accept_states
    if as.parity_state & 1 == 1
        return false
return true

Unless I'm overlooking something, each DFA state is treated at most twice, each time checking at most size children for required action.

吻泪 2024-12-28 23:52:30

看起来这只需要两个状态。

您的输入状态将是空字符串,并且也将是接受状态。将任何内容添加到字符串中都会将其移动到下一个状态,我们可以将其称为“奇数”状态,而不是使其成为接受状态。添加另一个字符串会让我们回到原始状态。

我想我不再确定术语是否属于 P 语言,所以如果你给我一个定义,我可以告诉你这是否合适,但这是最简单的 DFA 之一......

It would seem this only requires two states.

Your entry state would be empty string, and would also be an accept state. Adding anythign to the string would move it to the next state, which we can call the 'odd' state, and not make it an accept state. Adding another string puts us back to the original state.

I guess I'm not sure on the terminology anymore of whether a language is in P or not, so if you gave me a definition there I could tell you if this fits it, but this is one of the simplest DFA's around...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文