EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
Java代做
您的位置: 主页 > 编程案例 > Java代做 >
代做Java:CS代写之JAVA CS2230 Computer Science II: Data Structures binary - Java代做
发布时间:2021-07-25 10:38:10浏览次数:
CS2230 Computer Science II:Data StructuresHomework7ImplementingSetswith binarysearchtreesGoals for this assignment•Learn about the implementation of Sets usingbinary search trees, both unbalanced and balanced • Implement methods for a NavigableSet,includingcontainsandremove•Get more practice writing JUnit tests •Get more practicewith version control PurposeBinary search trees canbe used to build efficientSets thatperform lookups and inserts in □□(□□□□□□ □□)time, which is fairly efficient. As we ve seen in class, Sets are useful for applications where you need to look things up by a key like checking airline tickets or looking up the existence of a word in a dictionary.Inthishomework,youwill study the implementation of Sets using binary search trees. We have provided Java files that contain code for a Set implemented with an unbalanced binary search tree (BSTSet.java) and a Set implemented using an AVLTree(AVLTreeSet.java),andyourjobistofinishthem. SubmissionChecklistBy April 17, 11:59pm: answers to the PROGRESS_REPORT.txt in your GitHub repository. No slip days accepted.By April 20,11:59 pm: You should have changes in GitHub to the following files:•BSTSet.java •AVLTreeSet.java•BSTSetTest.java •AVLTreeTest.java (if you added optional tests) •answers.pdfSlip days: Your submission time is the date of the last commit we see in your GitHub repository. As usual, we willprocess slip days automatically, soyou do notneed to tell us you are using them. You will submit them via GitHub. Follow the directions in setup_hw7.pdf on Setup your own private repository to push your commits to . Before you are done submitting, you mustcheck the following.üDo the tests pass? üDid I write the required tests? üDoes mygithub.uiowa.edurepository reflectthe code I intend to turn in? (You must view this in your web browser,not inNetBeans.If stillin doubt, you can also clone yourcompleted code into a second NetBeans project and check it by running all the tests). GettingHW7Follow all the directions in setup_hw7.pdfPart 0Examine the TreeNode class.Inparticular,answerthefollowingquestionsforyourself(you do not need to submit the answers, but this partwill help you with the rest of the assignment).•How do you test if thisis a leaf? •How does isBST work? •What is the resultof toString() when called on the root TreeNode of the following tree?Part 1: Contains methodThe Set.contains method returns true if and only if the element exists in the Set. a)The BSTSetTest.java file has test cases for BSTSet. Devise three different tests for the contains method (put them in testContainsA,B, and C) so that you are confident that contains() works. Your tests for this part should be black box , that is, they don t depend on the implementation: they only call publicmethods of BSTSet (in this case, the constructor, add(), and contains()). Your 3 tests need to be different:that is,youraddmethods shouldbesuch thattheycausedifferentunderlying tree structures and there should be cases where contains() returns each true and false.b)Implement theBSTSet.containsmethod. Part 2: A method for NavigableSetTake a look at the NavigableSet interface. It adds a new methodsubSetto the methods already provided by Set. The subSetmethod requires that keys stored in the NavigableSet have a total order. Therefore, you ll see that the generictype is constrained to be a Comparable. The Comparable interface provides the compareTo method. public interface NavigableSet T extends Comparable T extends Set T Read the Java 8 API on Comparable https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.htmlto see what compareTo does. a)BSTSet implements theNavigableSet interface, so you needto provide an implementation of subSet. NavigableSet T subSet(T fromKey, T toKey) that returns anew NavigableSet that contains all elements□□,suchthat □□□□□□□□□□□□□□≤□□ □□□□□□□□□□. Your method must be efficient. That is, your algorithm should find fromKey quickly and once it finds toKey (or larger key) it should not look at any other nodes. For a balanced tree, your implementation should be faster than linear in N,whereNisthesizeoftheoriginalSet,assumingthat S N,whereSis the size of the subset. An implementation thatvisits entiresubtrees that are not in range [start, end) is probably O(N). An example of an O(N) algorithm would be: 1) perform an inorder traversal of the whole tree, inserting nodes into a List, then 2) iterate over the list to remove the elements not between start and end. The following tests in BSTSetTest.javaarerelevant tothis method:testSubSet1,2,3. b)You must write at least two more tests. •testSubSet4: It musttest adifferenttreestructureandrangethanthe other3tests. •testSubSetOutOfBounds: Test a situation where theoriginal Sethas elements but thesubset is the empty Set. Tips •The subMap method in Goodrich chapter 11.3 is a similar method to subSet. •You ll probably need one or more private helper methods and/or inner classes. •There are three basicapproaches we can think of: oBuild a whole List T of keys that are in-range using recursion then add the elements to a new BSTSet. oSame as above but skip the List T add directly to the BSTSet as you find them oDefine an inner class thatimplements Iterator T . It keeps a frontier (e.g., a Stack) to do the traversal. Advance the traversal after each call to next(). HINT: a preorder traversal requires seeing each node twice (once before visiting leftand once after) so may wantto mark nodes as visited or not. Call this iterator s next() in a loop, adding elements to a new BSTSet. Part 3: remove elements from an unbalanced BSTThe Set.remove method removes the element if it exists in the Set and returns true if the element was found. Part 3a: deleteMin The BSTSet.remove method will depend on the BSTSet.deleteMin method. This method takes a TreeNode n and removes the minimum element in the subtree rooted at n. Tips: •The two if-statement lines of deleteMin are pre conditions . Leavethem there!They will help with debugging•To perform the deletion you should use the method updateParent.It willgreatly simplify your implementation because it works whether you are changing the left or right child.We ve provided tests in BSTSetTest (called testDeleteMin*) to help you ensure deleteMin is correct before proceeding to the remove method.Part 3b: remove Implement theBSTSet.removemethod.Recallthat therearefourcasesforremoval in a BST: a)removed node is a leafb)removed node has only a leftchild c)removed node has only a rightchild d)removed node has two children Case d is the tricky one. Use the following algorithm, adapted from your textbook: 1)use deleteMin to delete the smallestelementin rightsubtree 2)use the data of the node returned by deleteMin to overwrite the data in the removed node. Take the time with some examples on paper (the remove test cases in BSTSetTest.java are one good source of examples) to convince yourself why the above algorithm works.There are several tests called testRemove* in BSTSetTest to help you debug. Part 4: Balanced treeThe BSTSet does not keep the tree balanced, and we know that an unbalanced tree can make contains/add/remove operations take O(N) in the worst case instead of O(log N). To improve your Setimplementation, you will complete a second class that uses a balanced binary search tree,AVLTreeSet. Notice that this class extends BSTSet, borrowing most of the functionality. We ve provided implementations of add and remove that call a balancing method to fix the balance property after an insertion or removal. Your job will beto complete the balancing functionality by implementing two methods •AVLTreeSet.rotateLeft •AVLTreeSet.rotateRightSee the commentsabove these methods to see a detailed description of what each method should do. Notice that the AVLTreeSet.balance method uses rotateLeftand rotateRightin combination to do the double rotation cases, so you don t have to directly implement double rotations. Tips: •as in the remove implementation, you should use the updateParentmethod to change whatnode is atthe top of the subtree. Itwill greatly simplifyyour code. •Note that the rotation changes the height of the tree, so make sure to call updateHeightat the end. (Do notcall updateHeightWholeTree)Allof the tests in AVLTreeSetTest.java should pass when the rotate methods work. Part 5: Stress testYou ve put a lot of effort into these Set implementations, so try it out on bigger data than the tiny test cases! We ve provided an example file StressTest.java. It times how long add() takes for 3 implementations of Set •BSTSet •AVLTreeSet • java.util.TreeSetThe program tries a uniform random distribution of inputs, as well as an increasing order of inputs. Answer the following in a file called answers.pdf (put it in the base of your repository). Visuals such as bar graphsare encouraged. Just make sure to explain them.a)What observations of heights and running times can you make from running StressTest? b)Give an explanation of the heights and running times you observed, based on what you know about the 3 implementations. Inotherwords,say why theheightsandrunningtimesarewhatthey are. (You can read about java.util.TreeSet at https://docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html)This part will be graded on these 2 criteria: •Did you answer the questions completely and specifically? Are your explanations accurate? •Are your answers concise and clear? Tips for Testingand Debugging•We ve provided a method BSTSet.bulkInsert()thatis helpful for creating a tree. •We have also provided an implementation of TreeNode.equals()so that trees can be compared properly in JUnit assert* methods.• Inyourtests,donotbuild your test trees manually.Use add()or bulkInsert().• IMPORTANT:themethodscheckIsBST (forBSTSet orAVLTreeSet)andcheckIsBalanced(for AVLTreeSet) are very helpful for debugging.Thesemethodsthrowanexceptionif theinvariants of the data structure are violated. Some of the testcases call them. You should use them in your own testcases and even within your code atplaces where you know the invariants should hold (for example,at theend oftheremovemethod). Extracredit (up to 5 points)Submission:put your work in thebase of yourGitHub repository in a file named extracredit.pdf.You may attempt this extra credit no matter how much of the rest of the assignment you complete. However, the effort-to-points ratio may notbe as high. The assignment is more open ended and allows for exploration and problem solving. Read the code in StressTest.java. You ll notice that it prints the height of the trees inside of the BSTSet and the AVLTreeSet. The height is not part of the Set/NavigableSet interfaces,yet weexposed it for our testing and debugging purposes.Incontrast,wecould not printouttheheight oftheunderlyingtreeinthejava.util.TreeSet.The particulars of the tree implementation are not exposed to the user. Take a look at the publicmethods of https://docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html.Discover interesting features of TreeSet s implementation. Here are some ideas:•Option1a:What algorithmis it? Look at the source code for TreeSet.Find out what algorithm/data structure TreeSetuses. Your explanation MUST include primary evidence of your findings (e.g., snippets of code that you refer to). We suggest starting in StressTest.java and right clicking on TreeSet and choosing an option under Navigate. In general the options under Navigate will help you explore the source code. •Option1b:Break the interface!Devise a way toapproximate the height of an instance of TreeSetwith elements in itwithout calling any privatemethods. For example, you might run experiments to figure out the asymptoticrun time of the publicmethods. You should attempt to isolate constant factors with control experiments. Your explanation MUST include plots, which you clearly describe and refer to. 代写CS Finance|建模|代码|系统|报告|考试编程类:C++,JAVA ,数据库,WEB,Linux,Nodejs,JSP,Html,Prolog,Python,Haskell,hadoop算法,系统 机器学习金融类:统计,计量,风险投资,金融工程,R语言,Python语言,Matlab,建立模型,数据分析,数据处理服务类:Lab/Assignment/Project/Course/Qzui/Midterm/Final/Exam/Test帮助代写代考辅导E-mail:[email protected]微信:BadGeniuscs 工作时间:无休息工作日-早上8点到凌晨3点如果您用的手机请先保存二维码到手机里面,识别图中二维码。如果用电脑,直接掏出手机果断扫描。

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。