0% found this document useful (0 votes)
40 views2 pages

SLOa First Homework Solution

This document contains 3 homework problems: 1) Design a Turing machine to reverse a string over an alphabet in linear space and time. 2) Design a RAM program to find the integer k such that min ≤ kn ≤ max, using constant space and time proportional to min/n. 3) For any regular language L, the space and time complexity of a Turing machine that simulates the corresponding finite automaton are both linear in the length of the input string.

Uploaded by

Alan Dvořák
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

SLOa First Homework Solution

This document contains 3 homework problems: 1) Design a Turing machine to reverse a string over an alphabet in linear space and time. 2) Design a RAM program to find the integer k such that min ≤ kn ≤ max, using constant space and time proportional to min/n. 3) For any regular language L, the space and time complexity of a Turing machine that simulates the corresponding finite automaton are both linear in the length of the input string.

Uploaded by

Alan Dvořák
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SLOa - First Homework

Roth, Michael
[email protected]

March 15, 2023

1 Design a Turing Machine, which implements a reversion of the input


string over the Latin alphabet Σ = {A, . . . , Z}.

To satisfy this problem, we will define a Turing Machine with two tapes, where the first tape stores the input string
and the final output.

First, the Machine writes the symbol from the first tape to the second tape, then shifts both tapes to the right.
This step is repeated until the Machine reaches the first empty symbol. At this point, both tapes contain the same
string.

When the first empty symbol is reached, we rewrite the empty symbol to # and shift the first tape right.

Lastly, the machine writes the symbol from the second tape to the first tape, then shifts the first tape right and
the second tape left. This step is repeated until the second tape reaches an empty symbol at the start of the tape.
Then, the machine halts.

Estimating space complexity is trivial, as the machine will take the input, double its length and add one additional
symbol. Additionally, it will need the amount of extra space on the second tape equal to the length of the input string.
Therefore, its space complexity is 3n + 1.

2 Design a RAM program, which for the input I = (min, max, n) computes
the number k such that min ≤ (k ∗ n) ≤ max. Let us assume, that all
the input numbers are greater than zero. After the HALT instruction,
the register r0 will contain the number k or -1 if such k does not exist.

RAM program calculating the k from the above problem will use these steps:

1. load the number n into r1 ,


2. load the number 1 into r2 (this will serve as the register for the number k)

3. load the number n from r1 into accumulator and check, if equation min ≤ r0 ≤ max holds. If it holds, load the
current r2 into the accumulator and halt. If r0 < min, continue to the next step, and if r0 > max, load -1 to r0
and halt.
4. increment the number in r2 by 1, add n from input to r1 and jump to step 3.

Note that in step 3, the order of evaluating the conditions matter.

1
The uniform space complexity of such a program will be constant, as the program will always use 3 input numbers,
accumulator and two extra registers. Therefore, it’s uniform space complexity is
uni
SΠ (I) = 6

The uniform time complexity of this program is proportional to the ratio of the min input and n input:

tuni
Π (I) = ⌈min/n⌉ × 9 + 4

The increment loop (step 3) takes 9 instructions, loading the values to registers at the start and end oof the
program takes 2 instructions each for a total of 4 extra instructions.

3 Let L be a regular language. Estimate functions f (n) and g(n) such that
L ∈ DT IM E(f (n)) and L ∈ DSP ACE(g(n))

For any regular language L we can define a Turing machine, that simulates the function of a finite automaton. Such
a Turing machine would have the same states and transition function as the simulated finite automaton. With every
transition will such a TM shift right, it will never rewrite anything on the tape nor will it ever shift left. Therefore,
the space needed on the tape is directly proportional to the length of the input and the space complexity is therefore
linear.

Regarding the time complexity, for the reasons described above, the TM will always perform at most the number
of steps equal to the length of the input string, as it will never add nor rewrite any symbol on the tape, only shift
right as long as the input string belongs to the regular language L. Therefore, the time complexity is also linear.

f (n) = g(n) = n (1)

Powered by TCPDF (www.tcpdf.org)

You might also like