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

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

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

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

EG1hao
网课代修代上,cs代写代考
Java代写
您的位置: 主页 > 编程案例 > Java代写 >
代写Java:algorithms代写 | 算法代写 - Java代写
发布时间:2021-07-25 20:54:22浏览次数:
}boolean isEmpty(): the implementation of the method isEmpty from the interfaceSolutionQueue.1Because that method will be used in automated tests, you need to make sure that it works well, even if your own code doesn’t use it.1.3 LightsOutThe class LightsOut is the one finding all the solutions. The technique used to find these solutions is known as a Breadth-First Search. It uses a Queue in which partial solutions are stored. At each iteration, the partial solution at the front of the queue is removed from the queue. The algorithm checks if that solution is in fact complete. If it is complete, it checks if it is correct (if it works as a solution), and if so it records it, else it discards it. If the solution is not complete, then the algorithm extends that solution in every possible way. Each newly extended solution is enqueued at the back of the queue. The algorithm starts with a single, completely unspecified solution in the queue, and stops once the queue is empty.For this assignment, the queue that you use should be an instance of the class ArrayListSolutionQueue which you need to provide. The set of Solution objects found by the algorithm are themselves stored directly in an ArrayList (not a Queue). Here is a sketch of the method solve, which uses a Breadth-First Search to find all the solutions of the game Lights Out for a board of size widthxheight.Result: The list of all valid solutions for a widthxheight board.Create a queue partialSolutions and an ArrayList instance solutions;Initialize partialSolutions to contain a solution for a widthxheight board in which no position is specified;while partialSolutions is not empty doTake  the front element out of the partialSolutions queue, call this current;  if current is fully specified and correct thenadd current to solutions; elseforeach possible extension of current doadd the extension to rear of the queue partialSolutions; endend endreturn solutions;ArrayList Solution solve(int width, int height): The method solve finds all the solutions to the Lights Out gamefor an initially completely “off” board of size widthxheight, using a Breadth-First Search  It returns an ArrayList containing all the valid solutions to the problem.During the computation of the solution, the method prints out a message each time a new solution is found, along with the total time it took (in milliseconds) to find that solution.main:Create a main method which calls the method solve and then prints out the number of solutions found, as well as the details of eachThe width and height used by the main are passed as runtime parameters to the program. If no runtime parameters are passed to the program, or if the parameters are incorrect, then a default value of 3 for both width and height is used.A few sample runs of the program are shown in Appendix B.2 Second Implementation [30 Marks]Our first solution works well on very small board, but quickly becomes unusable with slightly larger boards2.We can easily optimize our code by remarking that once a solution is sure to fail, there is no point in continuing to extend it to the end. That solution can be dropped immediately.Note that we build our solution systematically, working from left to right, top to bottom. So the positions that are above the  working line  have their neighbourhood already completely specified. If the conditions for a working solution are not met for these positions, then these conditions will not be met for any completed versions of that solution and that solution can be readily abandoned.We modify our class Solution to add the following method:2Can you figure out why the solution takes so much time as soon as the board contains more than a few positions?public boolean stillPossible(boolean nextValue):  this  method  returns  false  if  the  current  solution  would be impossible to finalize into a working solution, should it be extended from its current state with the value nextValue.Note that the method returns false if extending the current solution with nextValue would never  yield  a  working solution, and true otherwise. Returning true does not mean that the solution can necessarily be extended into a working solution. It merely means that we do not yet know if it is still possible.Note as well that this method should not modify the state of the object instance of Solution on which it       is called. It does not extend that solution with nextValue, it simply indicates if such an extension would annihilate its chance of leading to a working solution..You need to modify the method solve of the class LightsOut to take benefit of the method stillPossible andprovide a more efficient implementation.A few sample runs of the updated program are shown in Appendix C.3 (Bonus Question) Third Implementation [10 marks]An even more efficient implementation can be easily achieved. For this, we need to remark that once a solution can only be extended one way and remain a possibly valid solution, it will never be extendable two ways after that. In other words, if a partial solution can only be extended by either true or false and remain a possible solution, but not by both true and false and remain a possible solution, then no extension of that solution which can still yield a correct solution can be extended by both true and false either. Once a solution as only one way to be extended into a possible solution, it will remain that way until it either yield a solution, or it is shown not to lead to a workable solution.We can leverage this information in our search for solutions: in our breadth-first search, once a solution is locked into a single alternative mode (it can be possibly extended, but only one way) then we do not need to keep using our breadth-first search with it. We know that at that point that solution will only be extendable into a series of unique next solutions, with no alternatives along the way, so we can simply extend that solution “to the end” and see if we reach a working solution or not. This will save many queue operations and should make our program more efficient.To achieve this, we modify our class Solution to add the following method:public boolean finish(): this method assumes that solution is currently still extendable, but only one It keepsextending that solution with the one correct way that it finds at each step, until the solution is complete and correct, or shown to not be work. It returns true if and only if the solution is extended into a complete, working solution.That method does change the state of the object instance of Solution on which it is called. If it returns true, then that instance is now a complete, working solution.As you implement this method, pay attention to special cases regarding the dimensions of the board..You need to modify the method solve of the class LightsOut to use the method finish whenever it can andprovide a more efficient implementation.A few sample runs of the updated program are shown in Appendix D.Academic IntegrityThis part of the assignment is meant to raise awareness concerning plagiarism and academic integrity. Please read the following documents.https://www.uottawa.ca/administration-and-governance/academic-regulation-14-other-important-informathttps://www.uottawa.ca/vice-president-academic/academic-integrityCases of plagiarism will be dealt with according to the university regulations. By submitting this assignment, you acknowledge:I have read the academic regulations regarding academicI understand the consequences ofWiththe exception of the source code provided by the instructors for this course, all the source code isI did not collaborate with any other person, with the exception of my partner in the case of teamIf you did collaborate with others or obtained source code from the Web, then please list the names of your collaborators or the source of the information, as well as the nature of the collaboration. Put this information in the submitted README.txt file. Marks will be deducted proportional to the level of help provided (from 0 to100%).

所有的编程代写范围: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++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。