简体   繁体   中英

how to formally described this algorithm for turing machine?

Waring : This task was given by my professor who is 80 y/o and nobody understands what he sometimes wants, I do not expect more less standard approach to this problem, not just because the problem is difficult, but because my professor is old-school ex-ussr crazy guy ;) (he likes to make easy things complicated, just to explain why this is posted here)

This task is pure theory one, but I do not know how to formalize it with words Problem:

9 bits binary code is given on input, we have to print "0" in output if amount of bits with value "1" are two times less than amount of bits with value "0", if this condition is false that we have to print "1" in output.

What I proposed in my description is to introduce a counter, and then count bits that have value 1, then make an output based on this counter, but I was claimed to be an idiot and I was told that there's the way without the counter and I choose the hardest way. Does someone know the better way to determine what to output?

Thanks in advance, and sorry if description looks messy

As the TM reads the input bits, the state number must capture the number of bits seen, from 0 through to 9, so that we can recognize when we get to the end, and the number of 1 bits seen, with the relevant cases being 0, 1, 2, 3, and >=4.

There are less than 10*5=50 states required to encode all the relevant possibilities. When the machine enters one of the states indicating that 9 input bits have been seen, it writes a 0 if it indicates that 3 1s have been seen, or 1 otherwise, then stops.

Note that we didn't need to use the tape for storage -- the input language is regular so it can be decided with a finite state machine and unbounded storage is unnecessary.

While Matt is correct, you can generalize this problem to arbitrary input sizes using storage.

  1. Go to the beginning of the tape
  2. Move forward looking for an unmarked 1 . Mark it.
    • If you can't find an unmarked 1 , go to step 7.
  3. Go back to the beginning of the tape
  4. Look for an unmarked 0 . Mark it.
    • If you can't find an unmarked 0 , go to step 9.
  5. Look for another unmarked 0 . Mark it.
    • If you can't find an unmarked 0 , go to step 9.
  6. Go to step 1
  7. Go to the beginning of your input.
  8. Look for an unmarked 0 .
    • If you don't find one, output 0 . Halt.
  9. Output 1 . Halt.

This will work for any input size. Intuitively, we're looking for 2 0 s for every 1 in the input, making sure there are twice as many 0 bits as 1 bits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM