” 辅导COMP9020编程、 写作webCOMP9020 Assignment 2 2021 Term 2Due: Monday, 19th July, 12:00 (AEST)Submission is through WebCMS/give and should be a single pdf file, maximum size 2Mb. Proseshould be typed, not handwritten. Use of LATEX is encouraged, but not required.Discussion of assignment material with others is permitted, but the work submitted must be yourown in line with the Universitys plagiarism policy.Problem 1 (15 marks)Let S be a set.(a) Show that for any set T and any function f : S T, the relation R f ? S S, defined as:(s, s) R f if and only if f (s) = f (s)is an equivalence relation. (9 marks)(b) Show that if R ? S S is an equivalence Relation, then there exists a set T and a function fR : S Tsuch that:(s, s) R if and only if fR(s) = fR(s)(6 marks)Problem 2 (34 marks)Let R ? S S be any binary relation on a set S. Consider the sequence of relations R0, R1, R2, . . ., definedas follows:R0 := I = {(x, x) : x S}, andRn+1 := Rn (R; Rn) for n 0Suppose there exists i N such that Ri = Ri+1.(a) Prove that Rj = Ri for all j i. (6 Marks)(b) Prove that Rj ? Ri for all j 0. (4 marks)(c) If |S| = k, explain why Rk2 = Rk2+1. (4 marks)(d) Let P(n) be the proposition that for all m N: Rn; Rm = Rn+m. Prove that P(n) holds for all n N.Hint: Use results from Assignment 1 (6 marks)(e) If |S| = k, show that Rk2 is transitive. (4 marks)(f) If |S| = k, show that (R R)k2 is an equivalence relation. (6 marks)1(g)? If |S| = k show that (R R)k2 is the minimum (with respect to ?) of all equivalence relations thatcontain R. (4 marks)RemarkThe relation at the limita as n tends to infinity, R? = limn Ri, is known as the reflexive, transitiveclosure of R, and is closely connected to the Kleene star operator.aBecause Rj ? Ri ? S S for all j i, the Knaster-Tarski theorem ensures this limit always exists, even for infinite S.Problem 3 (20 marks)Let B = {0, 1} and consider the Function f : N B given byf (n) ={1 if n 0,0 otherwise.(a) Show that for all a, b N:(i) f (a + b) = max{ f (a), f (b)}(ii) f (ab) = min{ f (a), f (b)}(6 marks)From Problem 1, we know that R f ?NN, the relation given by:(m, n) R f if and only if f (m) = f (n)is an equivalence relation. Let E ? Pow(N) be the set of equivalence classes of R f , and for n N, let[n] E denote the equivalence class of n.We would like to define binary operations, and , on E as follows:[x] [y] := [x + y][x] [y] := [xy].The difficulty is that the operands [x] and [y] can have multiple representations (e.g. if z [x] then[x] = [z]), and so it is not clear that such a definition makes sense: if we take a different representation ofthe operands, do we still end up with the same result? That is, if [x] = [x] and [y] = [y] is it the case that[x + y] = [x + y] and [xy] = [xy]? Our next step is to show that such a definition makes sense.(b) Define relations , ? E2 E as follows:((X, Y), Z) if and only if there is x X and y Y such that x + y Z((X, Y), Z) if and only if there is x X and y Y such that xy Z(i) Show that is a function.(ii) Show that is a function.(6 marks)2Part (b) shows that the informal definition of and given earlier is well-defined, so from now we willview and as binary operations on E, that is , : EE E.(c) Show that for all A, B, C E:(i) A [1] = A(ii) A B = B A(iii) A (B C) = (A B) (A C)(8 marks)RemarkObjects that have a concept of addition () and multiplication () where:addition and Multiplication are associative,both operations have identities (see (c)(i)),addition is commutative (see (c)(ii)), andmultiplication distributes over addition (see (c)(iii))are known as semirings. We have already seen a number of semirings in this course:The natural numbers with usual addition and multiplication,Integers modulo n with addition and multiplication modulo n,Subsets of a set X with union and intersection,Languages with union and concatenation,Binary relations with union and relational composition (see Assignment 1),Matrices with matrix addition and matrix multiplication.Problem 4? (6 marks)Let f (n) be defined recursively as follows:f (0) = 0 f (n) = f (bn3c) + 3 f (bn5c) + n for n 1Show that f (n) O(n).Problem 5 (20 marks)A binary tree is a data structure where each node is linked to at most two successor nodes:3If we include empty binary trees (trees with no nodes) as part of the definition, then we can simplify thedescription of the data structure. Rather than saying a node has 0, 1, or 2 successor nodes, we can insteadsay that a node has exactly two children, where a child is a binary tree. That is, we can abstractly definethe structure of a binary tree as follows:(B): An empty tree, (R): An ordered pair (Tleft, Tright) where Tleft and Tright are trees.So, for example, the above tree would be defined as the tree T where:T = (T1, T2), whereT1 = (T3, T4) and T2 = (T5, ), whereT3 = T4 = T5 = (, )That is,A leaf in a binary tree is a node that has no successors (i.e. it is of the form (, )). A fully-internal node ina binary tree is a node that Has exactly two successors (i.e. it is of the form (T1, T2) where T1, T2 6= ). Theexample above has 3 leaves (T3, T4, and T5) and 2 fully-internal nodes (T and T1). For technical reasons(that will become apparent) we assume that an empty tree has 0 leaves and ?1 fully-internal nodes.(a) Based on the recursive definition above, recursively define a function count(T) that counts the numberof nodes in a binary tree T. (4 marks)(b) Based on the recursive definition above, recursively define a function leaves(T) that counts the numberof leaves in a binary tree T. (4 marks)(c) Based on the recursive definition above, recursively define a function internal(T) that counts the num-ber of fully-internal nodes in a binary tree T. (4marks)(d) If T is a binary tree, let P(T) be the proposition that leaves(T) = internal(T)+ 1. Prove that P(T) holdsfor all binary trees T. Your proof should be based on your answers given in (b) and (c). (8 marks)Problem 6? (5 marks)Let be a finite set, totally ordered by . Give a formal, recursive definition of the lexicographic orderinglex? ? ?.4Advice on how to do the assignmentCollaboration is encouraged, but all submitted work must be done individually without consulting some-one elses solutions in accordance with the Universitys Academic Dishonesty and Plagiarism policies.Assignments are to be submitted via WebCMS (or give) as a single pdf file.When giving answers to questions, we always would like you to prove/explain/motivate your an-swers. You are being assessed on your understanding and ability.Be careful with giving multiple or alternative answers. If you give multiple answers, then we willgive you marks only for your worst answer, as this indicates how well you understood the question.Some of the questions are Very easy (with the help of external resources). You may make use ofexternal material provided it is properly referenced1 however, answers that depend too heavily onexternal resources may not receive full marks if you have not adequately demonstrated ability/un-derstanding.1Proper referencing means sufficient information for a marker to access the material. Results from the lectures or textbook can beused without proof, but should still be referenced.请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。