CS 139 // 2020-03-10
$(q,a)\rightarrow (q',a',D)$
$q$
$a$
$q'$
$a'$
$D\in\{L,R\}$
A Turing machine $M$ is a 7-tuple: $$M = (Q, \Sigma, \Gamma, \delta, q_0, q_\text{accept}, q_\text{reject})$$
$M$
$$M = (Q, \Sigma, \Gamma, \delta, q_0, q_\text{accept}, q_\text{reject})$$
$Q$
$\Sigma$
$\Gamma$
$\Sigma\subseteq\Gamma$
$\sqcup\in\Gamma$
$q_0\in Q$
$q_\text{accept}\in Q$
$q_\text{reject}\in Q$
$$\delta:Q\times\Gamma\rightarrow Q\times\Gamma\times\{L,R\}$$
$\delta(q, a) = (r, b, L)$
$r$
$b$
Show that the following language is decidable $$A = \{w\in\{0,1\}^\ast \mid \text{the middle bit of }w\text{ is a 1}\}$$
$$A = \{w\in\{0,1\}^\ast \mid \text{the middle bit of }w\text{ is a 1}\}$$
; Mark first bit, then go find the right-hand side of the tape start 1 b r find_right start 0 a r find_right start a a r halt-reject start b b r halt-reject start _ _ r halt-reject<br> ; Skip over all bits until we find a blank symbol or marked symbol, ; then move left and switch to the "rightmost" state find_right 0 0 r find_right find_right 1 1 r find_right find_right _ _ l rightmost find_right a a l rightmost find_right b b l rightmost<br> ; Mark the rightmost bit, then go find the left-hand side of ; the tape rightmost 0 a l find_left rightmost 1 b l find_left rightmost b b r halt-accept rightmost a a r halt-reject<br> ; Skip over all bits until we find a blank symbol or marked symbol, ; then move right and switch to the "start" state find_left 0 0 l find_left find_left 1 1 l find_left find_left a a r start find_left b b r start
Show that the following language is decidable $$B = \{w\in\{0,1\}^\ast \mid \text{the second-to-last bit of }w\text{ is a 1}\}$$
$$B = \{w\in\{0,1\}^\ast \mid \text{the second-to-last bit of }w\text{ is a 1}\}$$
start 0 _ R q0 start 1 _ R q1 start _ _ R halt-reject<br> q0 0 _ R q00 q0 1 _ R q01 q0 _ _ R halt-reject<br> q1 0 _ R q10 q1 1 _ R q11 q1 _ _ R halt-reject<br> q00 0 _ R q00 q00 1 _ R q01 q00 _ _ R halt-reject<br> q01 0 _ R q10 q01 1 _ R q11 q01 _ _ R halt-reject<br> q10 0 _ R q00 q10 1 _ R q01 q10 _ _ R halt-accept<br> q11 0 _ R q10 q11 1 _ R q11 q11 _ _ R halt-accept
$q_\text{accept}$
$q_\text{reject}$
$M = (Q, \Sigma, \delta, q_0, F)$
$M' = (Q', \Sigma, \Gamma, \delta', q_0, q_\text{accept}, q_\text{reject})$
$Q' = Q\cup\{q_\text{accept},q_\text{reject}\}$
$\Gamma = \Sigma\cup\{\sqcup\}$
$$ \delta'(q,a) = \begin{cases} \delta(q,a)\quad\text{ if }q\in Q\text{ and }a\in\Sigma\\ q_\text{accept}\quad\text{ if }q\in F\text{ and }a=\sqcup\\ q_\text{reject}\quad\text{ otherwise} \end{cases} $$
Show that the following language is decidable $$C = \{w\in\{0,1\}^\ast \mid w\text{ has the same # of 0's and 1's}\}$$
$$C = \{w\in\{0,1\}^\ast \mid w\text{ has the same # of 0's and 1's}\}$$
mark0 0 x r find_right mark0 _ _ l final_check mark0 * * r mark0<br> find_right _ _ l mark1 find_right * * r find_right<br> mark1 1 x l find_left mark1 _ _ r halt-reject mark1 * * l mark1<br> find_left _ _ r mark0 find_left * * l find_left<br> final_check _ _ r halt-accept final_check x x l final_check final_check * * l halt-reject
$L$
$53, 7129, -22, 46$
$0$
$1$
Suppose I have a graph $G$ defined by:
$G$
digraph example { "1" [shape=circle] "2" [shape=circle] "3" [shape=circle] "4" [shape=circle] "5" [shape=circle] "6" [shape=circle]<br> "1" -> "2" "1" -> "4" "2" -> "1" "2" -> "3" "2" -> "5" "4" -> "3" "3" -> "5" "5" -> "1" "5" -> "6" "6" -> "5" }
V = {1,2,3,4,5,6} E = {(1,2),(1,4),(2,1),(2,3),(2,5),(4,3),(3,5),(5,1),(5,6),(6,5)}
$\langle G\rangle$
Show that the following language is decidable
$$L = \{\langle S, n\rangle \mid S\subseteq\mathbb{N}\text{ is finite and }n\in S\}$$
$n$
def decider(S, n): """Checks if n is an element of S<br> Parameters: S: a list of integers n: an integer """ ...
M = On input <S,n>, 0. Check to see if <S,n> is properly formatted; if not, immediately REJECT 1. For each element x in S a. Compare x to n b. If they are the same, then immediately ACCEPT; otherwise continue with the for-loop 2. If we checked all elements of S and still did not find n, then REJECT
Consider the language defined by
$$L = \{\langle p\rangle \mid p\text{ is a polynomial with integral roots}\}$$
M = On input <p> where p is a polynomial over variables x1,...,xk, 1. For each possible integral assignment of x1,...,xk: a. Evaluate the polynomial p with the current assignment b. If p evaluates to zero, then immediately ACCEPT 2. If no assignment ever evaluates to zero, then REJECT