I need to run a fourth-fourth search in Java for an assignment. I have 5x5 grid tiles (total 24 - 1 tile is 'empty'). To rearrange the tiles in the correct order, rearrange the tiles by moving 'empty' up, down, left or right.
To do this search, I have created an array list 'queue'. I have a method that takes the state in the 0 index of this array list, finds every legal move and then adds them at the end of the array list.
In principle, it continues till the 'Golstat' is finally found. The problem is that when I run the search, the 'row' arraylist is still getting bigger and bigger today I was running it for hours and still did not get the solution.
This suggests that I might have gone wrong with this solution and there is a better way for me to search fourth-fourth in Java I know that my solution works (finally ) When I use an initial condition which is not very different from the goaltest, it does not take much time to find the right path. However, I have been given an initial state to use, which unfortunately, there is no Golstate anywhere !!!
Any sign or suggestion will be greatly appreciated! First of all, I'm definitely using a real quoque object instead of an ArrayList.
First of all, I'm definitely using an actual quote object instead of an ArrayList. Here is the Java APP page on the line interface: - You can see that there are many implementers of the queue on the page, if you do not know what to choose, what a simple linklist will do. A big display of ArrayList will be a hit because it's only removing from the end faster, if you delete it from anywhere in the array, then it will be below everything ( slow )! ). You will finally be enqueuing and dequeuing in the beginning, therefore slow
Now you have not explicitly mentioned that you are removing items (removing them) again with them, So I think that you are, because it will be a reason.
Do you particularly want to use the fourth-first search? If I do the correct calculations, then there are 25! (Factual) combination, so that 15511210043330 9 85984000000 combination, which theoretically if you are searching for the fourth-first time, then your algorithm is likely to never end. Is not permission to search deeply before? If you should use a fourth-time search, then the only way to make it faster is to scrape those states which may not be due to an optimal solution. Not sure how you will go about it.
Comments
Post a Comment