350 likes | 533 Views
TM accepting strings with equal number of 0’s and 1’s. Thamer Al sulaiman. TM accepting strings with equal number of 0’s and 1’s. The T uring machine accepts strings such as: 001110, 1011. The Turing Machine rejects strings such as: 010, 11100 and so on. . Algorithm.
E N D
TM accepting strings with equal number of 0’s and 1’s Thamer Al sulaiman
TM accepting strings with equal number of 0’s and 1’s • The Turing machine accepts strings such as: 001110, 1011. • The Turing Machine rejects strings such as: 010, 11100 and so on.
Algorithm A possible algorithm to solve this problem is: • For each symbol: 0 (1) read from input tape, search for a matching 1 (0), and replace both symbols with another symbol (to ignore matched symbols in subsequent steps). • If the respective symbol is not found – the end of the string reached without matching symbol (which means the string contains an unequal number of 0s and 1s), then we reject. • If all 0s and 1s are matched, then accept.
Δ/Δ,R q A Δ/Δ,R • - q is the initial state, • R is the rejection state, • F is the acceptance state. 0/x,R 1/x,R x/x,R 0/0,R Δ/Δ,R Δ/Δ,R C R B 1/1,R 1/x,L 0/x,L 0/0,L D 1/1,L 1/x,R 0/x,R x/x,L Δ/Δ,R E x/x,R Δ/Δ,R F
Δ/Δ,R q A Δ/Δ,R 0/x,R 1/x,R x/x,R 0/0,R Δ/Δ,R Δ/Δ,R C R B 1/1,R 1/x,L 0/x,L 0/0,L D 1/1,L 1/x,R 0/x,R x/x,L Input string: 001 Δ/Δ,R E x/x,R q Δ001 Δ/Δ,R F
Δ/Δ,R q A Δ/Δ,R 0/x,R 1/x,R x/x,R 0/0,R Δ/Δ,R Δ/Δ,R C R B 1/1,R 1/x,L 0/x,L 0/0,L D 1/1,L 1/x,R 0/x,R x/x,L Input string: 001 Δ/Δ,R E x/x,R q Δ001 ⊢ ΔA001 Δ/Δ,R F
Δ/Δ,R q A Δ/Δ,R 0/x,R 1/x,R x/x,R 0/0,R Δ/Δ,R Δ/Δ,R C R B 1/1,R 1/x,L 0/x,L 0/0,L D 1/1,L 1/x,R 0/x,R x/x,L Input string: 001 Δ/Δ,R E x/x,R q Δ001 ⊢ ΔA001 ⊢ ΔxC01 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