Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Automata & Computation Expert

Assignment: Introduction to the Theory of Computation

Note that this is an assignment and can be submitted in groups.  In fact, it is highly encouraged.  This is long and designed for a group. But, keep in mind that if you divide the problems up and each person only does their share, you will be in big trouble during the midterm and final exams, when something similar comes up and you have no idea how to solve it. Do yourself a big favour and actively participate in the development of solutions to all problems.

Being aware of the fact that you have an exam in the middle your allotted time for this assignment, we subtracted 1 problem from the usual load (of 5 problems for each assignment). Still, we strongly encourage you not to postpone this to a point that you will stress yourself over finishing it in time for the deadline. Keep in mind that we cannot grant extensions. According to the rules of "arts and science", we cannot change the due date of an assignment unless it is put to a vote in all 3 classes, which is practically impossibility.

1. Suppose we are given n coins, all of which are identical, except one which is a counterfeit. Further, assume that the counterfeit coin has a different weight compared to the genuine coins. Consider the problem of determining which of the coins is the counterfeit, by using a balance scale. In a single weighing, we are allowed to place some coins on one side and some on the other, and compare the weights. There are 3 possible results: the scale balances, the left side is heavier, or the right side is heavier. We are interested in solving the problem using the fewest number of weighings (imagine you have to pay per weighing and you are trying to spend the least amount of money on this).

(a) For this part, assume that you know (as a fact) that the counterfeit coin is heavier than a genuine coin. Propose a divide and conquer algorithm that would find the counterfeit coin with the minimum possible number of weighings.

(b) Write a recurrence relation for the function C(n) that determines how many weighings your algorithm performs for an instance of size n (that is when the total number of coins is n), and then provide a closed form answer for the recurrence.

Note: we are not after the running time. we are after the number of times you need to use the scale, so we are not looking for an approximate answer (big-O) here. We are looking for an exact answer. But, keep in mind that this exact answer refers to the worst-case scenario for the number of weighings the algorithm requires. You don't have to prove your closed form, but show your work on how you got the answer.

(c)  Repeat part (a), but now with the assumption that you don't know whether the counterfeit coin is heavier or lighter than the genuine coins. Think carefully about your base case. It may be tempting to go with a simple variation of your answer from (a) for this. Resist the temptation, because there is a better algorithm.

(d)  Similar to part (b), write a recurrence relation for the function C(n) that determines how many weighings your algorithm from (c) performs for an instance of size n, and then provide a closed form answer for the recurrence.

For simplicity, assume n = 2k (is a power of 2) for parts (a) and (b) and assume n = 3k for parts (c) and (d). Note that this is also giving you a hint at what the algorithms should look like. Think about the hint. Present your algorithms in a simple pseudo code style (as in the style of the other algorithms given to you in this assignment, and also the algorithms you have in your course notes).

2. Consider the following pseudo code for a function Hop, where the input n ≥ 1 is an integer. We are interested in understanding what the function will print. As you can see there are 4 different print statements in the pseudo code and the code prints through these statements. For each of the strings "eeny", "meeny", "miny", and "moe" (hmmmm!), we would like to know how many times the string is printed if a call is made to Hop(n), for all n. So, again, we are interested in an exact number of printed statements and not the runtime or its asymptotic complexity. As a programmer, you may be interested in measuring things other than execution time about your program: for example, memory consumption.

There are several ways of doing this. You can solve this problem one string at a time, ignoring the rest of the print statements. That is a valid solution. Or, you can be a little smarter about it, and do less recurrence- solving type of work. Let's do that! For the purposes of this problem, you may assume that every n is a (non-negative) power of 2.

Hop(n) {

1       print("eeny")

2       if (n == 1) { return }

3       for (i = 1 to i n) {

4                print("meeny")

5                if (i is even) {

6                print("miny") 7            }

8                if (i == |n/3|) {

9                         Hop(n/2)

10                       print("moe")

11              } else if (i == |2n/3|) {

12                       Hop(n/2)

13              print("moe") 14                }

15     }

}

(a) Write a recursive function definition for the function E(n), where E(n) stands for the number of times "eeny" is printed when we call Hop(n).

(b) Give a closed-form for E(n). You don't have to prove anything, but show your work.  The closed-form answer cannot drop  from  the sky.

(c) Let O(n) stand for the number of times "moe" is printed when we call Hop(n). Provide and equality that defines O(n) based on E(n). Justify your answer.

(d) Write a recursive function definition for the function M (n), where M (n) stands for the number of times "meeny" is printed when we call Hop(n).

(e) Give a closed-form for M (n). You don't have to prove anything, but show your work. The closed-form answer cannot drop from the sky.

(f) Let I(n) stand for the number of times "miny" is printed when we call Hop(n). Provide an equality that defines I(n) based on M (n). Justify your answer.

This problem is much easier than it seems. If you feel a bit lost, then try running the code (carefully so that you don't miss anything) over a few small inputs (such as 1, 2, . . . ) so that you get a sense of how things are working, and have a few concrete numbers to test your answers on after you are done. Just be careful when you count things, and about what your base cases are in each case. Keep in mind that the point of doing (c) and (f) is not to compute these in the same manner (through solving a recurrence) as (a) and (d). But, to use the code structure to relate these two numbers together using simple expressions.

3. Consider an array A with integer elements. The following algorithm recursively finds and returns the smallest element in A[b . . . e].

Min(A, b, e)
1    If (b = e)
2    return A[b] 3    m = [(b + e)/2]
4    x = Min(A, b, m)
5    y = Min(A, m + 1, e)
6    If (x < y)
7    return x
8    else
9    return y

(a) Write the appropriate precondition and postcondition that specify the correctness of this function.

(b) Prove that the function is correct by showing that your specification from part (a) is inductive (which is not the same as asking for a complete induction proof of the correctness statement).

4. For two strings u, v, we say that v = uR  if string v is the reverse of the string u. Formally,

|u| = |v| ∧ ∀ 0 ≤ i < |u|, u[i] = v[|u| - 1 - i]

where |u| stands for the length of string u, and u[i] is referring to the character that is in the ith position of the string (assuming that the positions start from 0 and go to |u| - 1, similar to arrays).

For example, abcde = (edcba)R. Also, if u = abcde, then |u| = 5 and u[3] = d. Consider the algorithm below that reverses a string u ∈ Σ:

algorithm REV(u)
2    l := |u|
3    if l ≤ 1
4    return u
6    m := l div 2
7    v := REV(u[0 . . . m - 1])
8    w := REV(u[m . . . |u| - 1])
9    return wv

where u[i . . . j] is the substring of u from position i to position j (both inclusive). We also assume that strings are indexed from 0 to the length of the string. The goal is to prove that algorithm REV correctly reverses a string.

(a) Write pre and post conditions for REV .

(b) Prove that REV is correct by proving that your specification from (a) is inductive (which is not the same as asking for a complete induction proof of the correctness statement).

Hint: be careful with part (b). You may find yourself using a fact in your proof that needs a proof. You may want to prove that fact as a separate  lemma.

Note: the following problem is extra. You can skip it and only do the 5 problems above and get a full mark on your assignment. So, this is not officially part of your assignment 2. But, if you do it, any extra marks you gain will count towards your final grade. For example, if you get a full mark on assignment 2 and do B2 as well, then the extra 10 points will get you approximately an extra 1.36 mark towards your final course grade. Think of this as a way for you to do more work to compensate for some lost mark from somewhere else.

There is a catch. This problem will be marked harshly. You either have a perfect solution and get the full 10 points, or you make a mistake somewhere (no matter how small it is) and get nothing (i.e. zero).  This only applies to the marking of B1. Since this is a bonus problem, we will demand perfection. Also, bonus problems should not be discussed on Piazza or during the office hours or the tutorials. You should do this on your own (i.e. within your group).

(B2) Given a sorted array of distinct integers (i.e. no two different array cells hold the same value), we would like to find out whether there is an index i for which A[i] = i. Assume indices start from 0.

(a) Give a divide-and-conquer algorithm that runs in time O(log n). You do not need to justify the runtime for us. Just convince yourself that your algorithm is fast enough.

(b) Prove that your algorithm is correct by providing the relevant correctness specification for it and proving that that specification is inductive.

Automata & Computation, Computer Science

  • Category:- Automata & Computation
  • Reference No.:- M91527596
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in Automata & Computation

Prove or disprove the following proposed inference rules

Prove or disprove the following proposed inference rules for functional dependencies. A proof should be made by using the reflexive, augmentation, transitive, decomposition, union, and pseudotransitive rules. A disproof ...

Models of computation assignment -purpose - to improve and

Models of Computation Assignment - Purpose - To improve and consolidate your understanding of regular and context-free languages, finite-state and pushdown automata. To develop skills in analysis and formal reasoning abo ...

Models of computation assignment -purpose - to improve and

Models of Computation Assignment - Purpose - To improve and consolidate your understanding of regular and context-free languages, finite-state and pushdown automata. To develop skills in analysis and formal reasoning abo ...

Question 1a digital computer has a memory unit with 16 bits

Question 1: A digital computer has a memory unit with 16 bits per word. The instruction set consists of 122 different operations. All instructions have an operation code part (opcode) and an address part (allowing for on ...

Question 1hoare logic semantics for each of the parts below

Question 1 Hoare Logic Semantics For each of the parts below, justify your answer briefly. 1. For which programs S does {False} S {True} hold? 2. For which programs S does {True} S {False} hold? 3. For which programs S d ...

Iot and data analytics1 analyse the taskanalyse what is

IOT and data analytics 1. Analyse the Task Analyse what is expected of you. This includes careful reading of the assignment task as specified in the Subject Outline. The executive summary of the research project is to be ...

Question - design a state machine that will control a

Question - Design a state machine that will control a vending machine. The vending machine has 4 inputs, N, D indicating a nickel or dime was inserted as well as clk and an active high asynchronous reset. The vending mac ...

Prove or disprove the following proposed inference rules

Prove or disprove the following proposed inference rules for functional dependencies. A proof should be made by using the reflexive, augmentation, transitive, decomposition, union, and pseudotransitive rules. A disproof ...

Question - design a task or function that will check the

Question - Design a task or function that will check the parity of a word for odd parity. The input to the task/function is a 5-bit word called data_in. If the parity of input data_in is not odd increment an error count ...

Regular expressions automatacomputabilitytheory of

Regular expressions, automata/computability/theory of computation How would I go about interpreting regular expressions? For example, how would I interpret the following in English: (0+1)*011 0*1*2* 0^(+)1^(+)2^(+)

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As