Question 1

Alphabet , construct a DFA or NFA that accepts:

  1. Binary strings that being and end with .
digraph {
	label="(1) DFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; r;
	node[shape=circle];
	init->s
	
	s->p [label=0]
	s->q [label=1]
	q->r [label=1]
	q->q [label=0]
	r->q [label=0]
	r->r [label=1]
 
	# always fail
	p->p [label=0]
	p->p [label=1]
}

Fail

Does not check single length.

digraph {
	label="(1) NFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; q;
	node[shape=circle];
	init->s
	
	s->q [label=1]
	q->r [label=0]
	r->q [label=1]
}
  1. Strings that contain exactly three s.
digraph {
	label="(2) NFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; r;
	node[shape=circle];
	init->s
	
	s->p [label=1]
	s->s [label=0]
	p->q [label=1]
	p->p [label=0]
	q->r [label=1]
	q->q [label=0]
	
	r->r [label=0]
	r->t [label=1]
}

Correct

  1. Contain substring .
digraph {
	label="(3) NFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; u;
	node[shape=circle];
	init->s
 
	s->s [label=0]
	s->s [label=1]
	s->q [label=1]
	q->r [label=0]
	r->t [label=1]
	t->u [label=0]
	
	u->u [label=0]
	u->u [label=1]
}

Correct

  1. Regular language represented by expression .
digraph {
	label="(4) NFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; t;
	node[shape=circle];
	init->s
	
	s->p [label=1]
	
	p->q [label=0]
	q->r [label=1]
 
	r->q [label=0]
	r->t [label=1]
 
	p->t [label=1]
}

Correct

Alternative Solution

digraph {
	label="NFA"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; u;
	node[shape=circle];
	init->s
	
	s->q [label=1]
	q->r [label=0]
	r->t [label=1]
	t->u [label=1]
 
	q->t [label=ε]
	t->q [label=ε]
}

Question 2

Let .

  1. Which are accepted:
    1. : Yes
    2. : No
    3. : No
    4. : Yes

Correct

  1. All strings with the same number of s as s.

Correct

Question 3

denotes reversal of

  1. , , , ,

Correct

  1. Assumption: we only have one tape to work with High-level description:

    • Read first digit and remember whether 0 or 1.
    • Seek to end of string
    • Check whether last digit matches
    • Remove last digit
    • Seek to start and remove first digit
    • Seek to next digit until no digits are left Pseudo-code:

    qInit: if read _: state qAccept else read 0: state q0Seek else read 1: state q1Seek

    q0Seek: if read _: move left state q0Check else: move right state q0Seek

    q1Seek: if read _: move left state q1Check else: move right state q1Check

    q0Check: # read _ is invalid if read 1: state qReject else read 0: write _ move left state qSeekStart

    q1Check: # read _ is invalid if read 0: state qReject else read 1: write _ move left state qSeekStart

    qSeekStart: if read _: move right state qDelete else: move left

    qDelete: if read _: # palindrome of 1 char state qAccept else: write _ move right

     	state qInit
    

Correct

  1. Convert pseudo-code into a complete description of a Turing Machine
digraph {
	label="TM (implicit reject)"
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; qAccept;
	node[shape=circle];
	init->qInit
 
	# read first digit
	qInit->qAccept [label="_,_,-"]
	qInit->qSeek0 [label="0,0,>"]
	qInit->qSeek1 [label="1,1,>"]
	
	# seek to the end of the string
	qSeek0->qCheck0 [label="_,_,<"]
	qSeek0->qSeek0 [label="0,0,>"]
	qSeek0->qSeek0 [label="1,1,>"]
	qSeek1->qCheck1 [label="_,_,<"]
	qSeek1->qSeek1 [label="0,0,>"]
	qSeek1->qSeek1 [label="1,1,>"]
 
	# check if end of string matches
	qCheck0->qSeekStart [label="0,_,<"]
	qCheck1->qSeekStart [label="1,_,<"]
 
	# seek to start
	qSeekStart->qDelete [label="_,_,>"]
	qSeekStart->qSeekStart [label="0,0,<"]
	qSeekStart->qSeekStart [label="1,1,<"]
 
	# delete and restart process
	qDelete->qAccept [label="_,_,-"]
	qDelete->qInit [label="0,_,>"]
	qDelete->qInit [label="1,_,>"]
}
name: Binary Palindrome
init: qInit
accept: qAccept

// read first digit
qInit,_
qAccept,_,-

qInit,0
qSeek0,0,>

qInit,1
qSeek1,1,>

// seek to end of string
qSeek0,_
qCheck0,_,<

qSeek0,0
qSeek0,0,>

qSeek0,1
qSeek0,1,>

qSeek1,_
qCheck1,_,<

qSeek1,0
qSeek1,0,>

qSeek1,1
qSeek1,1,>

// check if end of string matches
qCheck0,0
qSeekStart,_,<

qCheck1,1
qSeekStart,_,<

// seek to start
qSeekStart,_
qDelete,_,>

qSeekStart,0
qSeekStart,0,<

qSeekStart,1
qSeekStart,1,<

// delete and restart process
qDelete,_
qAccept,_,-

qDelete,0
qInit,_,>

qDelete,1
qInit,_,>

Correct

Question 4

Show that no DFA can accept the language .

  • Assume a DFA accepts .
  • Let be equal to the number of states.
  • Let be , by definition for some .
  • By the pigeon-hole principle, there exists state which is visited at least twice.
  • Assume the first visit is at time and second at time .
  • Hence we have that, .
  • We have that accepts , but .
  • This is a contradiction.

This is the correct answer