Concept explainers
(Knight’s Tour: Brute-Force Approaches) In Exercise 6.24 we developed a solution to the Knights Tour problem. The approach used, called the ‘accessibility heuristic, generates many solutions and executes efficiently.
As computers continue increasing in power, we’ll be able to solve many problems with sheer computer power and relatively unsophisticated algorithms. Let’s call this approach brute-force problem solving.
- Use random number generation to enable the knight to walk around the chess board (in its legitimate L-shaped moves, of course) at random. Your
program should run one tour and print the final chessboard. How far did the knight get? - Most likely, the preceding program produced a relatively short tour. Now modify your program to attempt 1,000 tours. Use a one-dimensional array to keep track of the number of tours of each length. When your program finishes attempting the 1000 tours, it should print this information in a tabular format. What was the best result?
- Most likely, the preceding program gave you some “respectable tours but no full tours. Now “pull all the stops out” and simply let your program run until it produces a full tour. [Caution: This version of the program could run for hours on a powerful computer.] Once again, keep a table of the number of tours of each length and print this table when the first full tour is found. How many tours did your program attempt before producing a full tour? How much time did it take?
- Compare the brute-force version of the Knight’s Tour with the accessibility-heuristic version. Which required a more careful study of the problem? Which
algorithm was more difficult to develop? Which required more computer power? Could we be certain (in advance) of obtaining a full tour with the accessibility-heuristic approach? Could we be certain (in advance) of obtaining a full tour with the brute-force approach? Argue the pros and cons of brute-force problem solving in general.
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (9th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting out with Visual C# (4th Edition)
Concepts Of Programming Languages
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Python Please. An interesting puzzler for chess buffs is the Knight’s Tour problem, originally proposed by the mathematician Euler. Can the knight piece move around an empty chessboard and touch each of the 64 squares once and only once? We study this intriguing problem in depth here. The knight makes only L-shaped moves (two spaces in one direction and one space in a perpendicular direction). Thus, as shown in the figure below, from a square near the middle of an empty chessboard, the knight (labeled K) can make eight different moves (numbered 0 through 7). A: Draw an eight-by-eight chessboard on a sheet of paper, and attempt a Knight’s Tour by hand. Put a 1 in the starting square, a 2 in the second square, a 3 in the third, and so on. Before starting the tour, estimate how far you think you’ll get, remembering that a full tour consists of 64 moves. How far did you get? Was this close to your estimate? B: Now let’s develop a script that will move the knight around a chessboard…arrow_forwardDo you reach many, do you reach one? def knight_jump(knight, start, end): An ordinary chess knight on a two-dimensional board of squares can make an “L-move” into up to eight possible neighbours. However, we can generalize the entire chessboard into k dimensions from just the puny two. A natural extension of the knight's move to keep moves symmetric with respect to these dimensions is to define the possible moves as some k-tuple of strictly decreasing nonnegative integer offsets. Each one of these k offsets must be used for exactly one dimension of your choice during the move, either as a positive or a negative version.For example, the three-dimensional (4,3,1)-knight makes its way by first moving four steps along any one of the three dimensions, then three steps along any other dimension, and then one step along the remaining dimension, whichever dimensions that was. These steps are considered to be performed together as a single jump that does not visit or is blocked by any of the…arrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science. Ridbit begins with an integer n. In one action, he can perform one of the accompanying tasks: partition n by one of its appropriate divisors, or take away 1 from n in case n is more prominent than 1. An appropriate divisor is a divisor of a number, barring itself. For instance, 1, 2, 4, 5, and 10 are appropriate divisors of 20, however 20 itself isn't. What is the base number of moves Ridbit is needed to make to decrease n to 1? Input The principal line contains a solitary integer t (1≤t≤1000) — the number of experiments. The main line of each experiment contains a solitary integer n (1≤n≤109). Output For each experiment, output the base number of moves needed to lessen n to 1.arrow_forward
- Correct answer will be upvoted else downvoted. Computer science. Positive integer x is called divisor of positive integer y, in case y is distinguishable by x without remaining portion. For instance, 1 is a divisor of 7 and 3 isn't divisor of 8. We gave you an integer d and requested that you track down the littlest positive integer a, to such an extent that a has no less than 4 divisors; contrast between any two divisors of an is essentially d. Input The primary line contains a solitary integer t (1≤t≤3000) — the number of experiments. The primary line of each experiment contains a solitary integer d (1≤d≤10000). Output For each experiment print one integer a — the response for this experiment.arrow_forwardYou are a computer research scientist at Tesla, and your task is to create a computer vision application for self-driving cars to detect object and avoid collision. You know that Graham's scan is a method of computing the convex hull of a finite set of points in the plane. You decide to apply this algorithm to achieve the goal of your task. a) Suppose Graham's scan executes n points, where n >= 3. Prove that, at the end of the program, the stack S consists of, from bottom to top, exactly the vertices of convex hull in counter-clockwise order.arrow_forward. Implement a program that randomly generates 10 integers from -100 to 100, stores them in a 1D array, and finds their maximum value. Calculate the execution time of finding a maximum. Repeat the test for 10,000 and 10,000,000 numbers. Provide your results in the form of a table below and provide a small summary. Implement a Java program that will populate a 5x5 matrix with randomly generated integers from 0 to 100. (1) print your matrix in a table form. (2) modify your code to multiply all even numbers by 10 and print the matrix. Your output of questions (1) and (2) should match the format of the following sample outputs:arrow_forward
- Do you reach many, do you reach one? def knight_jump(knight, start, end): An ordinary chess knight on a two-dimensional board of squares can make an “L-move” into up toneight possible neighbours. However, we can generalize the entire chessboard into k dimensions from just the puny two. A natural extension of the knight's move to keep moves symmetric with respect to these dimensions is to define the possible moves as some k-tuple of strictly decreasing nonnegative integer offsets. Each one of these k offsets must be used for exactly one dimension of your choice during the move, either as a positive or a negative version. For example, the three-dimensional (4,3,1)-knight makes its way by first moving four steps along any one of the three dimensions, then three steps along any other dimension, and then one step along the remaining dimension, whichever dimensions that was. These steps are considered to be performed together as a single jump that does not visit or is blocked by any of the…arrow_forwardUse Sage to program Exercise 5.In 1202 AD, Leonardo Pisano asked the following famous problem:A certain man had a pair of rabbits together in a certain enclosedplace, and one wishes to know how many are created from the pair inone year when it is the nature for of them in a single month to bearanother pair, and in the second month those born bear also. Becausethe abovewritten pair in the first month bore, you will double it. therewill be two pairs in one month. One of these, namely the first, bears inthe second month, and thus there are in the second month three pairs;of these in one month two are pregnant, and in the third month 2pairs of rabbits are born, and thus there are 5 pairs in the month;...Explain how the rabbits reproduce. Create a list F where F[x] is the number ofrabbits in month x. (so F[0]=1, F[1]=2) Find F[12]. Find F[100].arrow_forward3D Array: Use python to solve this problem. We already know how to operate 2D arrays. Now we have to use 3D arrays in order to construct LCS with 3 parameters. Multidimensional array means multiple arrays of different dimensions or sizes can be held by a single array. We will learn about 3D arrays with an example. Suppose we want to store midterm and final marks separately of four different courses of three students in a single array. We can easily do it by using a 3D array. Python: for i in range(len(A)): print("Student: ",(i+1)) for j in range(len(A[i])): print("Course: ",(j+1)) print("Marks of Mid and Final: ") for k in range(len(A[i][j])): print(A[i][j][k],end=" ") print() print() OUTPUT: Student: 1 Course: 1 Marks of Mid and Final: 30 25 Course: 2 Marks of Mid and Final: 35 40 Course: 3 Marks of Mid and Final: 41 45 Course: 4 Marks of Mid and Final: 26 26 Student: 2 Course: 1 Marks of Mid and Final: 41 45…arrow_forward
- Warning- Don't use AI or copied answer. I'll reduce rating if I see these things.arrow_forwardCan you help please the previous question is therearrow_forwardCorrect answer will be upvoted else downvoted. Computer science. Michael is blamed for disregarding the social removing rules and making a danger of spreading Covid. He is currently shipped off jail. Fortunately, Michael knows precisely what the jail resembles from within, particularly since it's actual straightforward. The jail can be addressed as a square shape a×b which is separated into stomach muscle cells, each addressing a jail cell, normal sides being the dividers among cells, and sides on the border being the dividers prompting opportunity. Prior to condemning, Michael can ask his companions among the jail representatives to make (all around stowed away) openings in a portion of the dividers (counting dividers among cells and the furthest dividers). Michael needs to have the option to escape the jail after this, regardless of which cell he is set in. Be that as it may, he likewise needs to break as couple of dividers as could be expected. Your assignment is to…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education