practice_exam_2018-solutions

pdf

School

Royal Melbourne Institute of Technology *

*We aren’t endorsed by this school

Course

1107

Subject

Computer Science

Date

Oct 30, 2023

Type

pdf

Pages

2

Uploaded by ChefLionPerson918

Report
COSC 1105/1107 - Computing Theory Mock Exam Page 3 of 4 Question 4: Pushdown AWLOIMAA. ... ..o.titrte ettt 10 marks Consider the pushdown automaton M below (—X means popping X from the stack; +X means pushing X to the stack. The empty string is denoted €). a+X,b+Y b—V a—X,—X (2) (3 marks) Trace the execution of M with inputs aabcbcaa, aabebea, and abcbeaaa. (qo, aabcbeaa, €) = (qo, abcbeaa, X) = (go, bebeaa, XX) + (qo,cbcaa, Y X X) = (q1, beaa, YXX)F (q1,caa, XX) (g2, a0, X X) F (g2,a,X) F (ga, ¢, €) Accepted. ( ( qo, aabebea, €) - (qo, abebea, X) F (qo, bebea, X X) F (qo,cbca, Y X X) F (g1, bea, Y X X) - (q1,ca, X X) F (q2,a, X X) F g2, €, X) F (g2, €) Accepted. (qo, abcbcaaa, €) F (qo, bebeaaa, X) (qo, cbcaaa, Y X) F (q1, beaaa, Y X) = (q1, caca, X) F (q2,aaa,X) F {(q2,0a,¢€) Rejected. (b) (4 marks) Describe the language of M in set notation and informally. Solution: {aibicbica® | i > k,i,4,k > 0}. This is the set of strings beginning with a number of @’s followed by a number of b’s followed by a single ¢ then the same number of b’s as before then another single ¢ and finally no more a’s than in the first part of the string. (¢) (3 marks) How does the language of M change if we replace the transition from ¢, to go with 6(q1, €, €) = (g2, €) and we add the transition &(ga, €, €) = (g1, €) in M 7. In one to three sentences, briefly explain your answer. Solution: Strings in L{M) are now of the form w;cwsg, where wy,wz {a,b}, na(wz) < ng(wy) and np(wsg) = np(wi). In other words, there must be the same number of b’s on either side of the ¢, but no more a’s on the right than there are on the left. To see this, note that there is now no order constraint on how the stack may be emptied, and so any string over a, b will fill up the stack. However, we empty the stack in the reverse order to the input. Without the —X transition, this would mean that we = wy. With this extra transition, we can arbitrarily omit a’s from wo. Hence ws can be best specified as wy with an arbitrary number of a’s deleted. Question 5: Turing MACKINES . . ... oottt e 16 marks Consider the Turing machine M = ({0, 91, 92,3}, {0, 1, B}, #,6,q0,{gs}) where transition ¢ is defined as: 5 0 1 4 qo (QQa O,R) (qla l»R) (Q37#’L) a1 (qQ,laR) (QOalaR) (QS7#3L) @ | (¢0,0,R) (a1,0,R) (g3, # L) a3 (2) (2 marks) Draw the Turing Machine M. Solution: 1/LR (b) (4 marks) What is the outcome of the computation of M with the inputs #gp 000110010+ (the state is written immediately to the left of the symbol being read)? Briefly explain your answer. There is no need to give traces. Question 5 continues on the next page. .. COSC 1105/1107 - Computing Theory Mock Exam Page 4 of 4 Solution: Machine accepts as tape is left with string 000010011. (¢) (3 marks) Describe informally the result of a computation in M. Solution: Machine flips all 0’s that have been preceded by an odd number of consecutive 1’s to 1’s, and similarly, flips all 1’s that have been preceded by an odd number of consecutive 0’s to 0’s. (d) (7 marks) Provide a Turing machine M which given a string w over (0, 1)* behaves as follows: o If w contains an odd number of 1’s and an odd number of 0’s, then M converts w into the binary successor of w, i.e. M/ adds 1 to the binary number represented by w. e Otherwise, M converts all the 1’s to 0’s. For example, given the strings 100101, 10011 and 11111, your machine should terminate with outputs 100110, 00000 and 00000 respectively. You may use any notation for Turing machines and any variety of Turing machine that you wish. go = even number of 1’s and even number of 0’s; g1 = odd number of 1’s and even number of 0’s; g = even number of 1’s and odd number of 0’s; and g3 = odd number of 1’s and odd number of 0’s states q4 and g5 perform the binary addition of 1 to the number. Note that there must be at least one 0 in the string so there is no need to shift the left first blank symbol, the string with all 1’s will be fully translated into all 0’s. state gg performs the transformation of all 1’s into 0’s. 1/0 L #/#,LD/LL@ Question 6: Languages and Computability ............. i 15 marks (a) (2 marks) What is a decision problem? What decision is made in the case of a 3SAT problem? Solution: A decision problem is a problem whose solution is an answer for either yes or no. In the case of 3-SAT, the decision is whether or not a given set of clauses is satisfiable, i.e., whether there is an assignment of truth values to the variables which makes all of the clauses true. (b) (4 marks) Explain what a Universal Turing machine U is and what U (U, (M, w)) would be equal to. Solution: A UTM U is a Turing machine that is able to simulate an input TM M on an input string w, that is, U(M, w) = M(w). U(U, (M, w)) = U(M,w) = M(w). (c) (2 marks) Could there be an undecidable NP-complete problem? Justify your answer. Solution: No. If a problem is NP-complete, then it is in NP and so there is a NTM that solves it. Hence, it is decidable. (d) (7 marks) Prove that the problem of deciding any Turing Machine halts for some input is undecidable. Solution: Suppose there exists a TM X that can decide whether a TM. M halts for some input w is decidable. Let us then build a TM H (M, w) as follows. H(M,w) runs first builds M, which is like M but the first thing it does is to delete whatever is in the tape as input and write w in it. Basically, M™ behaves like M on w, regardless on the input. Then, H(M,w) will call X (M™). Clearly, M halts on w iff M* halts on any input string. Thus, H (M, w) solves the Halting Problem, a contradiction, and hence X cannot exist. End of mock exam paper
COSC 1105/1107 - Computing Theory Mock Exam (100 marks) Page 1 of 4 DISCLAIMER: This is a mock exam for practice purposes only. It may not represent the real exam, may have mistakes, or under- developed solutions. Doing well/bad on this exam does not guarantee success/failure on the real exam. The sample questions do not cover the entire course examination syllabuses. Students are strongly advised to study each and every part of the syllabus. Use this exam to find your strengths and weaknesses and to see how long it takes to do certain problems. One of the main obstacles of any CT exam is time management. Questions are not worth equal marks; attempt the easiest questions first. GOOD LUCK! Question 1; ComPlexity . .. ..ottt e et e e e e e 15 marks (a) (3 marks) Briefly explain the difference between approximation and heuristic algorithms. In which problems would you use such algorithms? Solution: An approximation algorithm is one that solves a simpler problem than the original and provides answers that may not be solutions but are “close” to being solutions. A heuristic algorithm always returns a correct solution and takes reasonable amount of time for most inputs. Such algorithms are used for problems which are intractable. (b) (2 marks) It is known that 3SAT is an NP-complete problem. What does that mean? Solution: It means that it is in NP and it is also NP-hard. Being in NP means there is a NDTM that solves the problem in poly time; being in NP-hard means that every NP problem can be reduced (in poly time) to 3SAT. (¢) (2 marks) Can a decision problem be NP-hard but not in NP? Briefly explain your answer. Solution: Yes, NP-hard requires only that all NP problems be reduced to the problem of concern. For example, a problem can be in EXPTIME and still be NP-hard but beyond NP, because no poly-time NDTM that can solve it. (d) (4 marks) Prove that 4SAT is NP-complete. Solution: We must show that 4SAT is in NP and in NP-hard. 4SAT is in NP: build a NDTM that first guesses (non- deterministically) a truth valuation for each: variable and then checks, in poly time, that it makes the whole 4SAT formula true. 4SAT is NP-hard (reduce 3SAT to 4SAT): given a 3SAT formula c, build formula o by extending each clause in o with a copy of an existing literal in the clause. Formula o has 4 literals in each clause, and « is satisfiable iff o’ is satisfiable. (e) (4 marks) Prove thatif f(n) O(g(n)), then 10 x f(n) O(g(n)). Solution: We know that there exist ¢ and ng such that f(n) < ex g(n), forall n > ng. Then, 10x f(n) < 10x (ex g(n)), and s0 10 X f(n) < (10 x ¢) X g(n)). So, we take ¢/ = 10 x ¢ and it follows that 10 x f(n) O(g(n)). Question 2: ChomsKy HIerarchy .. ... i i e et e et it et o niaeans 21 marks (2) Classify the languages below as either regular (R); context-free but not regular (CF); or recursively enumerable but not context-free (RE). You must give a brief (one sentence) justification of your choice. i. (2 marks) {a®h?ic% |i >0} Solution: RE. Have to match 7 twice so one stack won’t be enough. ii. (2 marks) {wicws | w1, we {a,b}*} U {widwsy | w1, ws {a,b}*} Solution: R. Union of two regular languages, equivalent to L((a|b)*(¢|d)(a|b)*) fuy (2 marks) {wewiws | w, w1, ws (a|b)*, |w| # |wi| + |wal} Solution: CFE. A PDA can push X for each letter in w and pop for each in w; and ws, and stack must end non-empty. iii. (b) For each of the following statements, is the statement true or fulse? Briefly explain each answer in one or two sentences. i. (2 marks) Regular expressions are as powerful as non-deterministic push-down automatas. Solution: False. Regular expressions are equivalent to NFAs, which are strictly less powerful than PDA. ii. (2 marks) Context-sensitive languages can be recognised by a TM with semi-infinite tape. Solution: True. Context-sensitive languages can be recognised by a linear-bounded TM, and semi-infinite tapes do not add power to TMs. iii. (2 marks) Non-deterministic Turing Machines are more powerful than deterministic ones. Solution: False. Non-determininism do not add expressivity power to Turing Machines. iv. (2 marks) Context-sensitive grammars are more powerful than PDAs. Solution: True. CS grammars are equivalent to linear-bounded TMs which are strictly more powerful than PDAs. (7 marks) Show, using the Pumping Lemma, that the language L = {(a | ¢)"b™ | n < m} is not regular. Solution: Assume that L is regular. Then the Pumping Lemma applies, i.e. that 3n such that for all w L with |w| > n,w = 1Yz, Yy # e, |vy| < nand zy*z Lforall 1 > 0. Let w = a™b™*!. Then w L and |w| > n, and so w = zyz. As |zy| < n, y is of the form o’ for some 1 < j < n. Hence zyyyz L, i.e. a®T27b™*! L, which is a contradiction, as 7 > 1. Hence L is not regular. (c S—’ COSC 1105/1107 - Computing Theory Mock Exam Page 2 of 4 Question 3: Nondeterministic Finite Automata (NFAS) ... ..ottt ans 23 marks Consider the NFA M below over the alphabet 3 of English letters. Note that stands for the empty string. ._> 6 b 0%z ()—=()—{=) (a) (3 marks) Provide two strings accepted by M and one string rejected by M. Solution: See next question. (b) (3 marks) Describe informally the language L(A]) of M. Solution: Strings containing either the world “hello” or “hi” (c) (3 marks) Briefly explain how the language of Al changes if ¢3 is made a final state. Solution: Strings containing either the world “hello” or “hi”, or ending with “h”. (d) (6 marks) Using the subset construction, build a Deterministic Finite Automaton (DFA) for the language of M. You can use abbreviations on transitions, such as a-z or £ \ {h}. Solution: >\ {h} (e) (8 marks) A decimal number consists of: (A) an optional + or sign; (B) a string of digits; (C) a decimal point; and (D) another string of digits.. Also, either the string of digits in (B) or (D) can be empty, but at least one of the two strings of digits must be nonempty. Finally, the decimal point appears if and only if the string of digits (D) is not empty. Draw the state diagram of an NFA which accepts decimal numbers. For example, the NFA should accept 132.424, 18888, and .87, but should reject 32.3.23, 187., and .98.1. You can use abbreviations such as 0-9 on transitions if you wish. Solution: Note that more compact (nicer) solutions exist.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: What are the blanks?
Q: When making a website, how many steps are involved? Explain in your own words what each step entails…
Q: A company reports the following: Cost of merchandise sold $1,861,500 Average merchandise inventory…
Q: Find the critical point of the function. Then use the second derivative test to classify the nature…
Q: What is the mass in grams of 1.33 x 1015 molecules of CO2?
Q: Questions and Problems 7. Explain the difference in enzyme activity before and after heating. 3. Why…
Q: The density of a substance is 1.5 grams per milliliter. What is the mass of 0.35 liters of the…
Q: David is driving a steady 25.0 m/s when he passes Tina, who is sitting in her car at rest. Tina…
Q: A galvanic cell is powered by the following redox reaction: MnO4(aq) + 2 H₂O(1) + 3 Cu* (aq) MnO₂…
Q: 7. A 90.0 kg man pushes on a 5.0 x 106 ton wall for 350 s but it does not move. How much work does…
Q: In this mechanim of receptor regulation, there is uncoupling of the signaling pathway. Even though…
Q: QUESTION 13 If the equation of a plane is given by 2x - 10y + 11z = 30 What is a normal vector to…
Q: The figure to the right shows the graph of a function. Match the function with its first derivative…
Q: GRAPHS AND FUNCTIONS Inverse functions: Quadratic, square root Consider the function f(x) =/x-1+10…
Q: s positioned first with its largest surface in contact with an nclined plane. The plane is tilted at…
Q: 10. A 13-foot ladder is placed against a vertical wall of a building, with the bottom of the ladder…
Q: Comet Craig-1959 moves along an ellipse with equation 49x² + 4y² - 196 = 0 (shown below) -10-9-8-7-6…
Q: Let z be a random variable with a standard normal distribution. Find the indicated probability.…
Q: How many moles are there in 23.6 g of FeF3? Answer to 2 decimal
Q: Which of the following statements are TRUE? (Check all that apply) OPython supports character data…
Q: Let f(x) = (x + 100)|x² - 11. Match the correct answer. Total umber of critical points Number of…
Q: Philadelphia Company has the following information for March: Sales $476,824 Variable cost of goods…