past_exam_04-solutions only

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

9

Uploaded by ChefLionPerson918

Report
COSC 1105/7 COMPUTING THEORY FINAL EXAM ANSWERS 2004 1. Complexity and Cryptography (7+4+3 = 14 marks) (a) Two programs had their execution times (in seconds) measured on the same data resulting in the table below. n Program 1 Program 2 (seconds) (seconds) 1 5 5 2 8 7 3 11 11 4 14 19 5 17 35 6 20 67 7 23 131 8 26 259 9 29 515 10 32 1027 Based on this data: i. Classify each of Program 1 and Program 2 as either tractable or intractable. (2 marks) Answer: Program 1 has complexity 3 n + 2 and hence is tractable. Program 2 has complexity 2 n + 3 and hence is intractable. ii. Calculate the time required for Program 1 for n = 20. (1 mark) Answer: 3 × 20 + 2 = 62 seconds. iii. Calculate the value of n for which Program 1 executes in the same time that Program 2 takes for n = 10. (2 marks) Answer: 3 n + 2 = 1027 means that n = 1025 / 3 = 342 seconds. (341.67 is acceptable). iv. Calculate the largest value of n for which Program 2 executes in under 20 seconds on a machine 1000 times faster. (2 marks) Answer: We need n such that 2 n + 3 20000, ie 2 n 19997. This is fine as an answer. This simplifies to n 14 (2 15 = 32 , 678). (b) A codebreaker has intercepted the following encrypted message. NBYUHMQYLCMZOHHS The codebreaker has partially broken this cipher, with the following letters known a b c d e f g h i j k l m n o p q r s t u v w x y z h i n r s t w a e so that the partially decrypted message reads as below. N B Y U H M Q Y L C M Z O H H S T H E A N S W E R I S ? ? ? ? ? i. Assuming this is a Caesar cipher, complete the decryption. (2 marks) Answer: The decryption shifts 6 to the right, so Z encodes F, O endcodes U, H encodes N and S encodes Y, making the complete message THEANSWERISFUNNY ii. Assuming that this is not a Caesar cipher (and so each letter may be encoded indepen- dently), calculate the number of ways in which the message could be completed. You may assume that no letter is encoded as itself. (2 marks) Answer: As there are 11 letters known, there are 25 - 11 = 14 possibilities for Z, and so 13 for O, 12 for H and 11 for S, making the total 14 × 13 × 12 × 11 = 24 , 024. 1
(c) Explain why the existence of a polynomial-time algorithm for primality testing does not affect the security of RSA. (3 marks) Answer: RSA encryption relies on factorisation being intractable. Primality testing is of no use to the attacker, as he or she already knows that n is not prime. Furthermore, existing probabilistic primality tests are significantly faster, and have not been helpful to attackers. 2. Chomsky Hierarchy (10+12 = 22 marks) (a) Classify the languages below as either regular context-free but not regular recursively enumerable but not context-free i. { a i b 2 i | i 1 } (1 mark) Answer: Context-free but not regular. ii. { a 2 i b 2 i c 2 i | i 2 } (1 mark) Answer: recursively enumerable but not context-free iii. { a i b j c i d j | i, j 1 } (2 marks) Answer: recursively enumerable but not context-free iv. { a i b j c k | i = j or j = k } (2 marks) Answer: context-free but not regular v. { w ∈ { a, b } * | w contains no more than 3 b s } (2 marks) Answer: regular vi. { w ∈ { a, b } * | w contains more a ’s than b ’s } (2 marks) Answer: context-free but not regular (b) Which of the following statements is true? Briefly explain your answer. i. Regular expressions are just as powerful as deterministic finite state automata. (2 marks). Answer: True. Every regular expression has an equivalent NFA, and hence DFA. ii. Context-free grammars are more powerful than pushdown automata. (2 marks). Answer: False. They are equivalent in power. iii. A pushdown automaton with two stacks is less powerful than a pushdown automaton with three stacks. (2 marks). Answer: False. They are both equivalent to Turing machines. iv. All regular languages can be recognised by a deterministic Turing machine. (2 marks) Answer: True. All such languages can be recognised by a DFA, which is a special case of a deterministic Turing machine. v. All context-free languages can be recognised by a deterministic pushdown automaton. (2 marks) Answer: False. Non-deterministic PDAs are more powerful than deterministic ones. vi. A nondeterminstic Turing machine cannot be converted into an equivalent deterministic Turing machine. Answer: False. It can be so converted (but at an exponential cost). (2 marks) 3. Grammars (4+5+4 = 13 marks) Consider the grammar G below. S AB | C | D A aA | Aa | aaA | AA | A | λ B bB | C C cCd | λ D dDc | cDd | DD 2
(a) Give a derivation of aaabbccdd from G . Which of the strings aaabbbbcccdd and aabbdddccc are derivable from G ? Briefly explain your answer (but there is no need to give full derivations). Answer: S AB aAB aaAB aaaAB aaaB aaabB aaabbB aaabbC aaabbcCd aaabbccCdd aaabbccdd aaabbbbcccdd is not derivable as it has an unequal number of c ’s and d ’s. aabbdddccc is not derivable, as to have d ’s before the c ’s we need to use D , but the rules for D do not result in any finite derivation. (b) Describe informally and in set notation the language of G . Answer: { a i b j c k d k | i, j, k 0 } . This is the language containing any number of a ’s followed by any number of b ’s followed by any number of c ’s followed by the same number of d ’s. (c) Describe how the language of G changes if the rule S SC is added to G . Compare this change to the one in which the rule B BC is added to G (but S SC is not). There is no need to write out the set notation for the new languages. Answer: If the rule S SC is added, this means that we can now have any number of repetitions of the groups of equal numbers of c ’s and d ’s, so that abccddcdcccdddcdcdcd is now derivable. If the rule B BC is added, then this has the same effect (ie both rule additions result in the same new strings being derivable). 4. Grammars (8+2+2 = 12 marks) Consider the informal specification of a language below. All Fine Dining programs commence with table(id) where id is an identifier, and conclude with pour , which may be optionally followed by tips , thanks or both. Apart from the above constructs a Fine Dining program consists of an entree section , a main section , a dessert section , a cheese section and a coffee section , in that order. Only the main section is compulsory; all of the others are optional. An entree section commences with starters , ends with sretrats and contains zero or more variable declarations. A main section optionally commences with plate and concludes with napkin and contains at least one gourmet dish . A gourmet dish is one of steak chicken fish lentils while boolean expression repeat gourmet dish stop doggy bag gourmet dish bag(identifier) A dessert section begins with sweets , ends with smile and contains one or two of the following keywords (repeats allowed): ice cream mousse pancakes fruit salad creme brulee smarties A cheese section commences with mouse , optionally ends with esuom and contains exactly three of the following keywords (repeats allowed): cheddar edam camembert brie swiss gorgonzola parmesan ricotta blue optionally followed by a single statement of the form repeat dessert section and cheese section until boolean expression A coffee section begins with drinks , ends with satisfaction and contains exactly one of the following keywords: cappuccino devonshire tea 3
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
Assume that rules have already been given for VariableDeclaration, Identifier, BooleanExpression, and all of the tokens and reserved words mentioned above (e.g. fish, pancakes, cappuccino, ... ). (a) Complete the following grammar for Fine Dining programs (i.e. write the grammar rules for Main, Desset and Coffee.). You needn’t worry about whitespace. FineDining table(Identifier) Entree Main Dessert Cheese Coffee pour Options Options Tips Thanks | Thanks Tips Tips tips | λ Thanks thanks | λ Entree starters VariableDeclaration sretrats | λ Cheese mouse Cheeses Cheeses Cheeses CheeseStatement EndCheese | lambda Cheeses cheddar | edam | camembert | brie | swiss | gorgonzola | parmesan | ricotta | blue CheeseStatement repeat Dessert and Cheese until BooleanExpression midλ EndCheese esuom | λ Main ... Dessert ... Coffee ... Answer: (Note that this is a simplification of a language specification used in an assignment). Main Plate Dishes napkin Plate plate | λ Dishes Gourmet | Gourmet Dishes Gourmet steak | chicken | fish | lentils | while BooleanExpression repeat Gourmet stop | doggybag Gourmet bag(identifier) Dessert sweets Sweet Sweet smile Sweet icecream | mousse | pancakes | fruitsalad | cremebrulee | smarties Coffee drinks Cuppa satisfaction Cuppa cappuccino | devonshiretea (b) Consider the following change to the second bullet point in the language specification above: “Apart from the above constructs a Fine Dining program consists of an entree section , followed by a main section , followed by any two of a dessert section , a cheese section and a coffee section in any order. None of these sections may be empty.”. For example a Fine Dining program can now have an entree section followed by a main section followed by a dessert section and a coffee section . However it may not have all five sections (entree, main, dessert, cheese, coffee). Write the corresponding grammar rule/s for FineDining. You may assume that rules are already defined for Entree, Main, Dessert, Cheese and Coffee. Answer: FineDining table(Identifier) Entree Main Others pour Options Options Tips Thanks | Thanks Tips Tips tips | λ Thanks thanks | λ Others Dessert Cheese | Cheese Dessert | Dessert Coffee | Coffee Dessert | Cheese Coffee | Coffee Cheese (c) Consider a further change to the second bullet point in the language specification above: “Apart from the above constructs a Fine Dining program consists of either an entree section , followed by a main section , or a dessert section followed by a coffee section , or a cheese section . None of these sections may be empty.”. 4
Write the corresponding grammar rule/s for FineDining. You may assume that rules are already defined for Entree, Main, Dessert, Cheese and Coffee. Answer: FineDining table(Identifier) Meal pour Options Options Tips Thanks | Thanks Tips Tips tips | λ Thanks thanks | λ Meal Entree Main | Dessert Coffee | Cheese 5. NFAs (3+3+2+5+4+6 = 24 marks) Consider the NFA M below in which q 3 is the only final state. 0 1 2 3 q 0 q 0 , q 1 q 0 q 0 q 0 q 1 q 1 , q 2 q 1 q 1 q 2 q 2 , q 3 q 2 q 3 (a) Which of the strings 30132, 000111222 and 0022111 are accepted by M ? Answer: 30132 and 000111222 are accepted. 0022111 is rejected. (b) Describe informally the language L ( M ) of M . Answer: Strings which end in 2, and contain at least one 0 and at least one 1 such that the final 1 comes after the final 0. (c) How does the language of M change if q 0 is made a final state? Answer: The language is then every string over { 0 , 1 , 2 , 3 } . (d) Give a DFA for the language of M . Answer: 0 1 2 3 0 01 0 0 0 01 01 012 01 01 012 01 012 0123 012 0123 01 012 0123 012 (e) Let M 1 be the machine with the transition δ ( q 3 , λ ) = { q 0 } added to M , and M 2 be the machine with the transition δ ( q 3 , 3) = { q 3 } added to M . How do L ( M 1 ) and L ( M 2 ) differ from L ( M )? If M 3 is the machine resulting from adding both transitions to M , does L ( M 3 ) = L ( M 1 ) L ( M 2 ) hold? Briefly explain your answer. Answer: L ( M 1 ) is a sequence of strings from L ( M ), so that L ( M 1 ) = ( L ( M )) + . L ( M 2 ) is the strings in which the final 2 comes after the final 1 which comes after the final 0, but, in contrast to L ( M ), need not end in 2. Clearly L ( M 1 ) L ( M 3 ) and L ( M 2 ) L ( M 3 ), and so L ( M 1 ) L ( M 2 ) L ( M 3 ). As 01230123 L ( M 3 ) but 01230123 L ( M 1 ) and 01230123 L ( M 2 ), we haev L ( M 3 ) L ( M 1 ) L ( M 2 ), i.e. L ( M 3 ) = L ( M 1 ) L ( M 2 ). (f) Draw the state diagram for an NFA over the alphabet { a - z, 0 - 9 , , } which recognises a list of items, each of which is either a bibliographic reference or chook detector reference, separated by commas. A bibliographic reference is a string of length at least 3 over { a - z } followed by a string of length at least 2 over { 0 - 9 } . A chook detector reference is a sequence of detector positions. A dectector position is one of the four characters n , s , e and w followed by a string over { 0 - 9 } of length at least 1. For example, the following should all be accepted by the NFA 5
hello99,n34s1n1n11,hbf02,bsfsbsfb11111111111111111 n1s2e3w4 goodbye03,superman04,rocky99,w43243434s21212,n4s2 but the following should not. he9329219292 ww1111111111111 Answer: 6. Chomsky hierarchy (5+4+3+3 = 15 marks) (a) Prove that there is no DFA for the language L 1 = { a i b i c i | i 0 } . Answer: Assume that L 1 is regular. Hence there is a DFA M which accepts L 1 . Let the number of states in M be k . Then by the Pumping Lemma for any w L 1 for which | w | ≥ k there exist x, y, z such that w = xyz , y = λ , | xy | ≤ k and xy i z L 1 i 0. Let w = a k b k c k . As | w | > k , the Pumping Lemma applies and so we have xyz = a k b k c k . As | xy | ≤ k , y must contain only a ’s and so y = a m for some 1 m k . Now consider xy 2 z = a k + m b k c k , and so xy 2 z L 1 , which is a contradiction. Hence L 1 is not regular. (b) Give a context-free grammar for the language L 2 = { a i b j c k | i = j, i, j, k 0 } Answer: S AC | BC A aAb | aA | a B aBb | Bb | b C cC | λ (c) Give an example of a string w a * b * c * for which w L 1 and w L 2 . Answer: aabbccc (d) Explain how your proof that L 1 is not regular would need to be adapted in order to show that L 2 is not regular. (Hint: consider how you could show that w L 2 ). Answer: To show that a string of the form a i b j c k is not in L 1 , we only need to show that either i = j , as in the proof above, or j = k . To show that a string of the form a i b j c k is not in L 2 , we need to show that i = j . Hence the proof would have to be adapted to show that xy 2 z = a k + m b j c i L 2 , i.e. that k + m = j . By choosing w to be a k b k + m c k , this can be achieved. 7. Pushdown automata (3+4+3 = 10 marks) Consider the pushdown automaton M below. Q = { q 0 , q 1 , q 2 } δ ( q 0 , a, λ = { ( q 0 , A ) } δ ( q 1 , a, A ) = { ( q 2 , λ ) } Σ = { a, b, c } δ ( q 0 , b, λ = { ( q 0 , B ) } δ ( q 2 , b, A ) = { ( q 2 , λ ) } Γ = { A, B } δ ( q 0 , b, B ) = { ( q 1 , λ ) } F = { q 2 } δ ( q 1 , a, B ) = { ( q 1 , λ ) } (a) Trace the execution of M with inputs aabbbaab , aabbabbb and aaabbaab . Answer: ( q 0 , aabbbaab, λ ) ( q 0 , abbbaab, A ) ( q 0 , bbbaab, AA ) ( q 0 , bbaab, BAA ) 6
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
( q 0 , baab, BBAA ) ( q 1 , aab, BAA ) ( q 1 , ab, AA ) ( q 2 , b, A ) ( q 2 , λ, λ ) Accepted. ( q 0 , aabbabbb, λ ) ( q 0 , abbabbb, A ) ( q 0 , bbabbb, AA ) ( q 0 , babbb, BAA ) ( q 0 , abbb, BBAA ) ( q 0 , bbb, ABBAA ) ( q 0 , bb, BABBAA ) ( q 0 , b, BBABBAA ) ( q 0 , λ, BBBABBAA ) ( q 0 , babbb, BAA ) ( q 1 , abbb, AA ) ( q 2 , bbb, A ) ( q 2 , bb, λ ) ( q 0 , bb, BABBAA ) ( q 1 , b, ABBAA ) ( q 0 , b, BBABBAA ) ( q 0 , λ, BABBAA ) Rejected. ( q 0 , aaabbaab, λ ) ( q 0 , aabbaab, A ) ( q 0 , abbaab, AA ) ( q 0 , bbaab, AAA ) ( q 0 , baab, BAAA ) ( q 1 , aab, AAA ) ( q 2 , ab, AA ) ( q 0 , baab, BAAA ) ( q 0 , aab, BBAAA ) ( q 0 , ab, ABBAAA ) ( q 0 , b, AABBAAA ) ( q 0 , λ, BAABBAAA ) Rejected. (b) Describe the language of M in set notation and informally. Answer: { a i +1 b j +1 ba j ab i | i, j 0 } . This is the set of strings which begin with a non-zero number of a ’s followed by a non-zero number of b ’s followed by a b and one less a than the number of b ’s followed by an a followed by one less b than the number of a ’s. (c) How does the language of M change if we add the transition δ ( q 0 , b, B ) = { ( q 0 , λ } to M ? Briefly explain your answer (but there is no need to give set notation for this language). Answer: The language of M increases, in that we can now insert arbitrarily mainly copies of bb anywhere in the string in the a i +1 b j +1 . 7
8. Turing Machines (4+3+6 = 13 marks) Consider the Turing machine M below. δ B 0 1 2 3 q 0 q 1 , B, R q 1 q 2 , B, L q 1 , 0 , R q 1 , 1 , R q 1 , 2 , R q 1 , 3 , R q 2 q 3 , 0 , L q 4 , 1 , L q 3 , 2 , L q 4 , 3 , L q 3 q 5 , B, R q 3 , 0 , L q 3 , 0 , L q 3 , 2 , L q 3 , 3 , L q 4 q 6 , B, R q 4 , 0 , L q 4 , 1 , L q 4 , 3 , L q 4 , 3 , L q 5 q 3 , 0 , L q 3 , 0 , L q 3 , 2 , L q 3 , 3 , L q 6 q 6 , 0 , R q 6 , 1 , R q 6 , 3 , R q 6 , 3 , R (a) Trace the computation of M with initial configuration q 0 B 0123 B . What is the outcome of the computation of M with the inputs 3312212 and 0201010 ? Briefly explain your answer (but there is no need to give a full trace for these inputs). Answer: q 0 B 0123 B Bq 1 0123 B B 0 q 1 123 B B 01 q 1 23 B B 012 q 1 3 B B 0123 q 1 B B 012 q 2 3 B B 01 q 4 23 B B 0 q 4 133 B Bq 4 0133 B q 4 B 0133 B Bq 6 0133 B B 0 q 6 133 B B 01 q 6 33 B B 013 q 6 3 B B 0133 q 6 B For 3312212 it goes to the end of the string, and then passes back through it, changing the 1’s to 0’s. When it his the initial blank, it then goes into an infinite loop, oscillating between the initial blank and the first 3 in the string. For 0201010 it behaves similarly, i.e. converts all the 1’s to 0’s and then loops. (b) Describe informally the result of a computation in M . Answer: If the string ends in 1 or 3, all 2’s are changed to 3’s and the machine halts. If the string ends in 0 or 2, all 1 are changed to 0’s and the machine loops. (c) Let w ∈ { 0 , 1 } * . We say w is eggy if either of the following conditions hold: w contains more 0’s than 1’s w contains the same number of 0’s as 1’s and the first character of w is 0 We say w is sticky if either of the following conditions hold: w contains more 1’s than 0’s w contains the same number of 1’s as 0’s and the first character of w is 1 Give a Turing machine which takes a string over { 0 , 1 } and overwrites the second blank after the string with 1 if the string is eggy and 0 if the string is sticky. For example, given the initial tape contents B 0000011 B , a correct output would be B 0000011 B 1. Note that any other output with the final 1 is also correct (so that you can destructively 8
over-write the input string during computation if you wish). Hence BBBBBBBBB 1 and B 0000000 B 1 are also correct. Similarly, for the initial tape contents B 10101111 B and B 0011 B , correct outputs include B 10101111 B 0 and B 0011 B 1 respectively. You may use any notation for Turing machines and any variety of Turing machine that you wish. Note that you may also use other characters in the tape alphabet if you wish. Answer: End of exam paper 9
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: An X-ray of a female's tibia shows that the proximal epiphysis is in the early stages of fusion but…
Q: A closed box with a square bottom has a total surface area (all 6 sides) of 400 square inches.…
Q: would you solve the story problem: In Keenan’s art project, for every 28 triangles, there are 12…
Q: A variable x is normally distributed with mean 21 and standard deviation 5. Round your answers to…
Q: Translate to an inequality. He swims at most 2.4 hours per day.
Q: Tepaid Insurance The balance in the prepaid insurance account, before adjustment at the end of the…
Q: Describe the procedure a computer system uses to transform analog sound into digital sound.
Q: (d) Because of increased competition, Deegan is considering reducing the price of model DRB such…
Q: Demonstrate that the equation x10 + y10 - z10 = 5 has no integer solution. (work with modulo 11)
Q: Solve the system below. Note that the solution can be found mentally, without the use of a…
Q: What is the horse's forelimb Class 1 lever MA? Type your numeric answer and submit
Q: Donna is looking into investing a portion of her recent bonus into the stock market. While…
Q: A football is kicked with an initial velocity of 10 m/s at an angle of 25°. If it hits the ground…
Q: 25 What is the measure of ZABC in the circle below? D m/ABC = 88 62 A B degrees
Q: 1.Ammonia is both a donor and an acceptor of hydrogen in hydrogen-bond formation. Draw a diagram…
Q: A soft drink machine outputs a mean of 29 ounces per cup. The machine's output is normally…
Q: So, I'm trying to figure out how to do this kind of problem. y(y4)5 I'm not sure how to go
Q: Consider the following hypothetical unbalanced equation: J2 + D --> D2J5 What is the theoretical…
Q: If 5x² + y² = 61 then evaluate when z = 3 and y = 4. (Answer accurate to two decimal places.)
Q: Suppose the utility function of a consumer is characterized by U(x1, x2) = 2x1 + 3x2. Find the…
Q: The following table of values gives a company's annual profits in millions of dollars. Rescale the…
Q: Sphere has mass of 10kg and radius of 10cm It’s spinning at 30 rads a second. It stops in 60 seconds…