This is the first of two courseworks for Theory of Computation. On completing this

coursework, you should be able to:

• Read and write finite state automata (both deterministic and non-deterministic).

• Understand regular languages and regular expressions.

• Convert regular expressions to and from finite state automata.

• Recognise languages and apply arguments to show that a language is not regular,

including use of the pumping lemma.

• Create finite state transducers.

The subject matter follows lectures 1-3 (and associated class exercises).

Information

Module marks

This coursework is worth 15% of the Theory of Computation module mark. This

coursework is marked out of 100.

Grading

Solutions will be graded according to their correctness, including accuracy of the

representation and syntactic correctness.

i) Generate six integers x, y, z, u, v and w from your login. Call the first digit of your login

i, the second j and the third k. The numbers are defined as follows:

1. x = ⎡(k+1)/2⎤. That is, add 1 to k and divide by 2 then take the ceiling (round up).

2. y = ⎡(j+1)/2⎤

3. z = ⎣k/5⎦+4. That is, divide k by 5, take the floor (round down) and add 4.

4. u = ⎡(j+1)/4⎤

5. v = ⎡(i+1)/2⎤

6. w = 6-y

For example, if your login was abcd036, then i = 0, j = 3, k = 6 and you would find that

x=4, y=2, z=5, u=1, v=1 and w=4.

Consider the incomplete NFSA (indeed disconnected), with Σ = {a,b,c}, represented as a

transition diagram below:

Complete this NFSA (to give NFSA V) by indicating start and accept states and adding

four transitions, as follows (where the values of x, y, z, u, v, w are as calculated above;

recall that ((s,α),t) is a transition from state s to state t, labelled with α):

1. x is the start state

2. y is the accept state

3. ((3,c),z)

4. ((4,c),u)

5. ((v,ε),w)

6. ((1,a),y)

Represent V as a transition diagram.

ii) Now take the NFSA V produced in part i) and transform it into a DFSA that accepts

the same language. It is not necessary to draw its transition diagram, a transition table

including an indication of start and accept states is enough.

[30 marks]

Question 2

Apply the algorithm contained in the proof of Kleene’s Theorem to construct a regular

expression that generates the language recognised by the NFSA V from Question 1. The

solution should clearly show each step of the process.

[25 marks]

4

Question 3

Suppose Σ is the last two letters in your login (if these are the same, that’s OK) and call

those letters α, β in the order in which they occur. Let i, j be the second and third digits

of your login. That is, if your login is abcd123, Σ = {c,d}, α=c, β=d, i = 2, j = 3. Consider

the following language:

{αnβjαn+iβ| n≥ 0}

For example, if Σ = {c,d} and i = 1, j = 2, then this language is {cnd2cn+1d| n≥ 0} and

ccddcccd is in the language, but ccdcccd, ccddccc, ccddccd are not.

Is your language regular? If so, give a regular expression for the language. If not,

demonstrate this using the Pumping Lemma for regular languages.

[25 marks]

Question 4

Recall that a finite state transducer (see Sipser, page 87) is like a deterministic FSA,

except that in addition to consuming input, each transition can produce an output.

Notationally, a transition looks like this:

where b is the consumed input and x is the output.

• An ant lives in a grid world, an n x m two-dimensional grid of cells. Within this grid

is a pheromone trail leading to the tree whose leaves are the ant’s food, each point of

the trail consists of one cell. The trail is continuous, with one spot being either to the

north, south, east of west of the next spot; no diagonals are allowed.

• The ant can detect what is straight ahead of it: either nothing [including the grid

boundary] (E), the trail (P) or the tree (T).

• If the ant detects the tree it moves forward one cell (F), then will remain in the same

place (S) forever.

• If the ant detects a trail cell, it moves forward one cell (F).

• If the ant detects empty it moves 90 degrees to the left (L) and again detects what is

ahead of it. If it again detects empty it will move 90 degrees to the right (R) twice

and again detect what is ahead of it.

• If the ant has detected empty ahead, to the left and to the right it remains in the

same place forever.

• You may assume that at any point the ant will be able to detect at most one cell in

the pheromone trail (there are no choices available).

• Using these rules the ant, initially at the west side of the grid facing east, can start at

the beginning of a pheromone trail and follow it to the tree. For example (where the

coloured cells are the trail, and the arrow is the ant pointing forwards

# Theory of computation

The question are in the image attached some questions refer to book attached. I need solutions to all the questions in the images They are around 60 questions. Also as a sample work please attach your answer to problem number 157 in the image IMG_3265.JPG in hand written while sending me hanshake request or message. I want all the question to be solved with step by step and handwritten clearly.

# Theory of Computation.

CS 345: Spring, 2014

1.

a. A distinguishing difference between a depth-first traversal and a breadth-first traversal is the data structure used to hold the nodes to be visited. What data structure is used with a breadth-first traversal? [5 points]

b. If the structure to be traversed is a complete, balanced binary tree (every non-leaf node has two children), does a breadth-first traversal require more or less space to store the nodes to be visited than a depth-first traversal? [5 points]

2.

The textbook presents a solution to the problem of finding a minimum cost spanning tree of a graph by Prim’s algorithm (the Lazy Contractor). What algorithm paradigm does this algorithm use? [10 points]

3.

Write the pseudocode for a function called pre-order(). This is a recursive function which performs a pre-order traversal of a binary tree. The function takes one parameter, n, which is a node of a tree; and it calls a function visit(), which processes the node. [10 points]

CS 345: Spring 2014

Page 1 of 7

Midterm D

4.

a. Under what conditions might a divide-and-conquer algorithm be useful? [10 points]

b. Describe either a problem that can be solved using a divide-and-conquer algorithm or a well-known algorithm that implements a divide-and-conquer approach. [10 points]

5.

What are the steps necessary to create a dynamic programming solution to a problem? [10 points]

CS 345: Spring 2014

Page 2 of 7

Midterm D

6.

When a problem can be solved by backtracking, it makes use of a bounding function. Describe the purpose of the bounding function. [10 points]

7.

Graph 1 represents a map of cities. A traveler wants to go from city A to city B.

a. What path would a greedy algorithm take? [10 points]

b. What path would a dynamic programming algorithm take? [10 points]

CS 345: Spring 2014

Page 3 of 7

Midterm D

8.

Draw a depth-first spanning tree for Graph 3 starting from node A. Process the children of a node in alphabetical order. [10 points]

CS 345: Spring 2014

Page 4 of 7

Midterm D

9.

Below is a method that calculates a binomial coefficient.

/* int [][] BC = new int[m][n] and int EMPTY = -1 are defined globally. In addition, BC has been initialized to EMPTY before the method is called. */ public int binomialCoefficient( int m, int n ) { if( (m == 0) || (m == 1) ) return 1; else if( (n == 0) || (n == m) ) return 1; else if( (n == 1) || (n == (m-1)) ) return m; else { if( BC[ m – 1 ][ n – 1 ] == EMPTY ) BC[ m – 1 ][ n – 1 ] = binomialCoefficient ( m-1, n-1 ); if( BC[ m – 1 ][ n ] == EMPTY ) BC[ m – 1 ][ n ] = binomialCoefficient ( m-1, n ); return ( BC[ m – 1 ][ n – 1 ] + BC[ m – 1 ][ n ] ); } }

a. What algorithmic paradigm is it using? [5 points]

b. Justify your answer. [5 points]

CS 345: Spring 2014

Page 5 of 7

Midterm D

10.

a. Describe what it means when an algorithm is partially correct. [5 points]

b. Describe what it means when an algorithm is totally correct. [5 points]

c. Describe the purpose of a convergent. [5 points]

CS 345: Spring 2014

Page 6 of 7

Midterm D

This page is scratch paper. It may be removed from the exam, and it does not need to be turned in with the exam.

CS 345: Spring 2014

Page 7 of 7

Midterm D

Basic Topics

Chapter 4

:

Algorithm Paradigms

•

Trees

•

Traversals and Searches

•

Depth

–

First: pre

–

order, in

–

order, post

–

order

•

Breadth

–

First

•

Divide

–

and

–

Conquer

•

Greedy

•

Dynamic Programming

•

Memoization

•

State Space Search

•

Backtracking

•

Branch and Bound

•

Problems

•

N

–

Queens

•

Knight

’

s Tour

•

Stack Permutation

•

Subset Sum

•

Maximum Subsequence Sum

•

Slobovian Coin

•

Knapsack

•

Minimum Cost Spanning Tree

•

Shortest Path

Chapter 5:

Algorithm Verification

•

Assertions and Invariants

•

Convergence

•

Verification Conditions

•

Partial and Total Correctness

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT