{"id":2965,"date":"2023-02-20T00:11:11","date_gmt":"2023-02-20T00:11:11","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/adv-design-analy-of-algorithm\/"},"modified":"2023-02-20T00:11:11","modified_gmt":"2023-02-20T00:11:11","slug":"adv-design-analy-of-algorithm","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/adv-design-analy-of-algorithm\/","title":{"rendered":"ADV DESIGN &amp; ANALY OF ALGORITHM"},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a java discussion question and need an explanation and answer to help me learn.<\/p>\n<p><span class=\"textlayer--absolute\">In class we have seen implementations of several methods for a scapegoat tree data structure in Java. For this <\/span><br \/> <span class=\"textlayer--absolute\">assignment, you will implement four methods as outlined below in Java. <br \/> <\/span><span class=\"textlayer--absolute\">0.<\/span><span class=\"textlayer--absolute\">Use the code from class \/ Canvas as a starting point or start yourself from scratch to have a class <\/span><br \/> <span class=\"textlayer--absolute\">ScapegoatTree<\/span> with generic key-value nodes. <br \/> <span class=\"textlayer--absolute\">1.<\/span><span class=\"textlayer--absolute\">Write <\/span><span class=\"textlayer--absolute\">postOrder<\/span> and <span class=\"textlayer--absolute\">preOrder<\/span> walk methods which take no input and return a list of tree nodes in the <br \/> <span class=\"textlayer--absolute\">respective order. <br \/> <\/span><span class=\"textlayer--absolute\">2.<\/span><span class=\"textlayer--absolute\">Override the <\/span><span class=\"textlayer--absolute\">toString<\/span> method of the Scapegoat tree class. Use the appropriate form of in-order, pre-order, <br \/> <span class=\"textlayer--absolute\">or post-order walk to form a string of all current keys which recursively contains parent(children) pairs. Adapt <\/span><br \/> <span class=\"textlayer--absolute\">your method from the methods you implemented in Exercise 1. As an example, if a parent has a left and a right <br \/> <\/span><span class=\"textlayer--absolute\">child who in turn have left and right grandchildren, your return string would look like <br \/> <\/span><span class=\"textlayer--absolute\">parent.key(left.key(lleftgrand.key<\/span><span class=\"textlayer--absolute\">(&#8230;), <\/span><span class=\"textlayer--absolute\">lrightgrand.key<\/span><span class=\"textlayer--absolute\">(&#8230;)), right<\/span><span class=\"textlayer--absolute\">.key(<\/span><span class=\"textlayer--absolute\">&#8230;<\/span><span class=\"textlayer--absolute\">))<\/span><span class=\"textlayer--absolute\">. <br \/> <\/span><span class=\"textlayer--absolute\">If exactly one of the children is <\/span><span class=\"textlayer--absolute\">null<\/span><span class=\"textlayer--absolute\">, print a space in its place. If both children are <\/span><span class=\"textlayer--absolute\">null<\/span><span class=\"textlayer--absolute\">, the parent is actually <\/span><br \/> <span class=\"textlayer--absolute\">a leaf and no recursion should be executed and no parentheses should be printed. <br \/> <\/span><span class=\"textlayer--absolute\">For example, the tree in Figure 1 in the Galperin\/Rivest 1993 paper should yield the string <br \/> <\/span><span class=\"textlayer--absolute\">2(1,6(5(4(3, ), ),15(12(9(7,11(10, )),13( ,14)),16( ,17( ,18)))))<\/span><span class=\"textlayer--absolute\">. <br \/> <\/span><span class=\"textlayer--absolute\">Hint: It is probably easiest to create the return string while traversing (instead of after traversing) similar to <\/span><br \/> <span class=\"textlayer--absolute\">collecting the nodes in the <\/span><span class=\"textlayer--absolute\">inOrder<\/span> method shown in class. That means you would need a mutable string object. <br \/> <span class=\"textlayer--absolute\">Since Java the String type is immutable, use one of the two mutable Java string types. <br \/> <\/span><span class=\"textlayer--absolute\">3.<\/span><span class=\"textlayer--absolute\">Write a public method <\/span><span class=\"textlayer--absolute\">successor<\/span> which finds the successor of a given key by finding the successor node and <br \/> <span class=\"textlayer--absolute\">returning the key of that node. If a successor does not exist, return the original key. Recall that the successor of <\/span><br \/> <span class=\"textlayer--absolute\">a node n<\/span> is either the minimum node in the right subtree of <span class=\"textlayer--absolute\">n<\/span> or the first parent of node <span class=\"textlayer--absolute\">n<\/span> for which <span class=\"textlayer--absolute\">n<\/span> is located <br \/> <span class=\"textlayer--absolute\">in the left parent sub-tree. <br \/> <\/span><span class=\"textlayer--absolute\">4.<\/span><span class=\"textlayer--absolute\">Write a public method <\/span><span class=\"textlayer--absolute\">predecessor<\/span> which finds the predecessor of a given key by finding the predecessor <br \/> <span class=\"textlayer--absolute\">node and returning the key of that node. If a predecessor does not exist, return the original key. Recall that the <\/span><br \/> <span class=\"textlayer--absolute\">predecessor of a node n<\/span> is either the maximum node in the left subtree of n or the first parent of node n for <br \/> <span class=\"textlayer--absolute\">which <\/span><span class=\"textlayer--absolute\">n<\/span> is located in the right parent sub-tree. <br \/> <span class=\"textlayer--absolute\">5.<\/span><span class=\"textlayer--absolute\">Test and debug your methods. Provide test runs in form of a main (driver) file in which you create appropriate <\/span><br \/> <span class=\"textlayer--absolute\">variables, fill the tree with data from the provided JSON file, and run some cases to show your methods work. <br \/> <\/span><span class=\"textlayer--absolute\">Do not forget to upload <\/span><span class=\"textlayer--absolute\">Main.java<\/span> and <span class=\"textlayer--absolute\">ScapegoatTree.java<\/span><span class=\"textlayer--absolute\">, as well as a screen shot of test runs. Recall <\/span><br \/> <span class=\"textlayer--absolute\">that the Gson<\/span> library needs to be included by going to File\u00e2\u2020\u2019Project Structure\u00e2\u2020\u2019Libraries\u00e2\u2020\u2019+\u00e2\u2020\u2019from Maven, <br \/> <span class=\"textlayer--absolute\">and then search for com.google.gson.Gson. <br \/> <\/span><span class=\"textlayer--absolute\">Each of the problems 1 \u00e2\u20ac\u201c 5 will be graded according to the following rubric for a total of 20 points. <br \/><\/span><\/p>\n<p><span class=\"textLayer--absolute\">SCORE<\/span> <span class=\"textLayer--absolute\">4<\/span> <span class=\"textLayer--absolute\">3<\/span> <span class=\"textLayer--absolute\">2<\/span> <span class=\"textLayer--absolute\">1<\/span> <span class=\"textLayer--absolute\">0<\/span> <br \/><span class=\"textLayer--absolute\">SKILL LEVEL<\/span> <span class=\"textLayer--absolute\">Response gives <\/span><br \/><span class=\"textLayer--absolute\">evidence of a <\/span><br \/><span class=\"textLayer--absolute\">complete <\/span><br \/><span class=\"textLayer--absolute\">understanding of <\/span><br \/><span class=\"textLayer--absolute\">the problem; is <\/span><br \/><span class=\"textLayer--absolute\">fully developed; is <\/span><br \/><span class=\"textLayer--absolute\">clearly &#8212;&#8212;4<br \/><span class=\"textLayer--absolute\">communicated.<\/span> <br \/><span class=\"textLayer--absolute\">Response gives the <\/span><br \/><span class=\"textLayer--absolute\">evidence of a clear <\/span><br \/><span class=\"textLayer--absolute\">understanding of <\/span><br \/><span class=\"textLayer--absolute\">the problem but <\/span><br \/><span class=\"textLayer--absolute\">contains minor <\/span><br \/><span class=\"textLayer--absolute\">errors or is not <\/span><br \/><span class=\"textLayer--absolute\">fully <\/span><br \/><span class=\"textLayer--absolute\">communicated&#8230;&#8230;.3<\/span><br \/><span class=\"textLayer--absolute\">Response gives <\/span><br \/><span class=\"textLayer--absolute\">evidence of a <\/span><br \/><span class=\"textLayer--absolute\">reasonable <\/span><br \/><span class=\"textLayer--absolute\">approach but <\/span><br \/><span class=\"textLayer--absolute\">indicates gaps in <\/span><br \/><span class=\"textLayer--absolute\">conceptual <\/span><br \/><span class=\"textLayer--absolute\">understanding. <\/span><br \/><span class=\"textLayer--absolute\">Explanations are <\/span><br \/><span class=\"textLayer--absolute\">incomplete, vagu<\/span><span class=\"textLayer--absolute\">e, <\/span><br \/><span class=\"textLayer--absolute\">or muddled&#8230;&#8230;2<\/span><br \/><span class=\"textLayer--absolute\">Response gives <\/span><br \/><span class=\"textLayer--absolute\">some evidence of <\/span><br \/><span class=\"textLayer--absolute\">problem <\/span><br \/><span class=\"textLayer--absolute\">understanding <\/span><br \/><span class=\"textLayer--absolute\">but contains <\/span><br \/><span class=\"textLayer--absolute\">major math or <\/span><br \/><span class=\"textLayer--absolute\">reasoning errors&#8230;&#8230;1<\/span><br \/><span class=\"textLayer--absolute\">No response or <\/span><br \/><span class=\"textLayer--absolute\">response is <\/span><br \/><span class=\"textLayer--absolute\">completely <\/span><br \/><span class=\"textLayer--absolute\">incorrect or <\/span><br \/><span class=\"textLayer--absolute\">irrelevant&#8230;&#8230;0<\/span><br \/><\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;m working on a java discussion question and need an explanation and answer to help me learn. In class we have seen implementations of several methods for a scapegoat tree data structure in Java. For this assignment, you will implement four methods as outlined below in Java. 0.Use the code from class \/ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[654],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/2965"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=2965"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/2965\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=2965"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=2965"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=2965"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=2965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}