Related questions
Number of Nodes expanded: 361
TIme Taken: 0.238
Memory Used: 704kb
Algorithm:
The algorithm for the given program can be summarized as follows:
-
Initialization: Initialize the state of the problem by defining a class "Board" which takes a list of tiles as input and calculates the size of the board based on the length of the list.
-
Node Definition: Define a class "Node" which represents the node in the search tree. A node consists of state, parent, and previous action.
-
Generate Puzzle: Create a random puzzle by generating a list of numbers from 0 to (size*size) - 1 and shuffle the list.
-
Get Children: Given a parent node, this function generates its children by simulating the four possible actions (left, right, up, down) on the empty tile.
-
Find Path: Given a node, this function backtracks from the node to the root node to find the solution path.
-
BFS Function: The function "run_bfs" implements the breadth-first search algorithm. It takes the root node as input and returns the solution path, the number of nodes expanded, and the total time taken. The function uses a deque to implement the frontier, a list to keep track of explored nodes, and the "get_children" function to generate children from the parent node.
-
Main Function: The main function takes input from the console, calls the "run_bfs" function to solve the puzzle, and shows the output.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- True or False? In Java, an array is a primitive type that need not be instantiated.arrow_forwardGuitarString.java Create a data type to model a vibrating guitar string. Write a class named GuitarString that implements the following API: public class GuitarString // Creates a guitar string of the specified frequency, // using a sampling rate of 44,100. public GuitarString(double frequency) // Creates a guitar string whose length and initial values // are given by the specified array. public GuitarString(double[] init) // Returns the number of samples in the ring buffer. public int length() // Plucks this guitar string by replacing the ring buffer with white noise. public void pluck() // Advances the Karplus-Strong simulation one time step. public void tic() // Returns the current sample. public double sample() // Tests this class by directly calling both constructors // and all instance methods. public static void main(String[] args)arrow_forwardComputer Science JAVA #7 - program that reads the file named randomPeople.txt sort all the names alphabetically by last name write all the unique names to a file named namesList.txt , there should be no repeatsarrow_forward
- Question 2. package sortsearchassigncodeex1; import java.util.Scanner; import java.io.*; // // public class Sortsearchassigncodeex1 { // public static void fillArray(Scanner inputFile, int[] arrIn){ int indx = 0; //Complete code { arrIn[indx] = inputFile.nextInt(); indx++; } }arrow_forwardDefine a class called Book. This class should store attributes such as the title, ISBN number, author, edition, publisher, and year of publication. Provide get/set methods in this class to access these attributes. Define a class called Bookshelf, which contains the main method. This class should create a few book objects with distinct names and store them in an ArrayList. This class should then list the names of all books in the ArrayList. Enhance the program by providing a sort function, which will sort the books in ascending order of their year of publication. Create a few more Bookobjects with the same names but with different edition numbers, ISBNs, and years of publication. Add these new Book objects to the ArrayList, and display the book list sorted by book name; for duplicate books of the same name, sort the list by year of publication. (Hint: You will need to define a comparator class that takes two Book objects as parameters of the compareTo This method should do a two-step...arrow_forwardcan you explain the code with comments import randomrandom.seed = 1class array: def __init__(self, valuelist): self.atos = valuelist.copy() # this variable is the array that holds the data def additem(self, value): # adds a item to the array self.atos.append(value) def printarray(self): # prints the self.atos print(self.atos) def __contains__(self, key): # To test the binary search change the "__linearsearch" to "__binsearch" return self.__binsearch(key) def __linearsearch(self, key): # Implements the linear search to find an item in the array for item in self.atos: if item == key: return True return False def __binsearch(self, key): temp = sorted(self.atos) # Implements the binary search to find an item in the array temp. This implements an iterative bin search algorithm. low = 0 high = len(temp) - 1 while low <= high:...arrow_forward
- Please create a Java class that has the following data attributes and methods: private int count - number of customers in the array private customer Record[] data - array of customerRecord objects public customer List() constructor that should initialize memory for data array and count value public void getCustomerList(String fileName) - reads a file call fileName which is a text file containing lines (records) of customer data. This method fills the data array with the records from the file. The file will not have more than 100 records and will have the following format (where customer Number is an integer, firstName and lastName are Strings, and balance is a float: customerNumber firstName lastName balance public customerRecord getCustomer(int customerNumber) - returns the object corresponding to the customer with customerNumber. If the customer number is not in the array, return null. public void enter CustomerRecord(customerRecord new_record)...arrow_forwardReadInstructor. The class will: – Create an array of instructor objects – Read the instructors.txt file – Create an Instructor object for each line of input and store the object in the array. – After closing the file, it will print out a line for each instructor in the array. Input file:Mary Smith 1991 50000.00 John Jones 2000 90000.00 Terry Seidel 1992 51000.00 Jessica Terrell 2000 91000.00arrow_forwarddictionaries = [] dictionaries.append({"First":"Bob", "Last":"Jones"}) dictionaries.append({"First":"Harpreet", "Last":"Kaur"}) dictionaries.append({"First":"Mohamad", "Last":"Argani"}) for i in range(0, len(dictionaries)): print(dictionaries[i]['First']) ************************************************* please modity the above code to "Add an ‘if’ statement(s) to the loop in your solution in Exercise 7 to only show the full name if the first name is "Bob" or if the last name is "Kaur".arrow_forward
- for the class ArrayAverage write a code that calculates the average of the listed numbers with a double result for the class ArrayAverageTester write a for each loop and print out the resultarrow_forwardJava Write a code fragment that prints the values stored in an array named totals backwards.arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY