How many backtracks occur

Assignment Help Mathematics
Reference no: EM13926811

A chessboard contains 64 squares that form 8 rows and 8 columns.

The most powerful piece in the game of chess is the queen because it can attack any other piece within its row, within its

column, or along its diagonal.

The Eight Queens problem asks you to place eight queens on the chessboard so that no queen can attack any other queen.

Complete all the methods in Queens.java that have a comment saying "To be implemented for Homework 5". You must also

write a driver that uses the Queens class to place the queens on the board in a manner that no queen can attack any other queen.

Your driver must also make the call to display the chess board with your computed solution(s).

Extra Credit:

 Revise the program that you just wrote for the Eight Queens problem so that it answers the following questions:

How many backtracks occur? That is, how many times does the program remove a queen from the board?

How many calls to isUnderAttack are there?

How many recursive calls to placeQueens are there?

 You can begin the Eight Queens problem by placing a queen in the second square of the first column instead of the first square.

You can then call placeQueens to begin with the second column.

This revision should lead you to a new solution.

Write a program that finds all solutions to the Eight Queens problem.

Instead of using an 8-by-8 array to represent the board in the Eight Queens program, you can use a one-dimensional array to

represent only the squares that contain a queen.

Let col be an array of eight integers such that

col[k] = row index of the queen in column k + 1

For example, if col[2] = 3, then a queen is in the fourth row (square) of the third column that is, in board[3][2] .

Thus, you use col[k] to represent a queen.

This scheme requires that you also store information about whether each queen is subject to attack. Because only one queen

per column is permitted, you do not have to check columns. To check for a row attack, define an array rowAttack such that

rowAttack[k] is nonzero if the queen in column k + 1 can be attacked by a queen in its row.

To check for diagonal attacks, observe that diagonals have either a positive slope or a negative slope. Those with a positive

slope are parallel to the diagonal that runs from the lower left corner of the board to the upper right corner. Diagonals with a

negative slope are parallel to the diagonal that runs from the upper left corner to the lower right corner.

Convince yourself that if board[i] [j] represents a square, then i + j is constant for squares that are in a diagonal with a

positive slope, and i - j is constant for squares that are in a diagonal with a negative slope. You will find that i + j ranges from

0 to 14 and that i - j ranges from -7 to +7. Thus, define arrays posDiagonal and negDiagonal such that posDiagonal[k] is true

if the queen in column k + 1 can be attacked by a queen in its positive-sloped diagonal, and negDiagonal[k] is true if the

queen in column k + 1 can be attacked by a queen in its negative-sloped diagonal.

Reference no: EM13926811

Questions Cloud

Philosophy & the individual approach for advocating : Advocates and mediators are two very rewarding carriers as they assist the community and people to bring justice and peaceful life. However, they also face many challenges in their profession.
What payments are required at the end of each of five years : The bank will charge Deseret a $50,000 loan- processing fee. What payments are required at the end of each of the five years? What is the effective, pretax cost of this loan?
While there are a number of factors : While there are a number of factors from a variety of sources that can influence whether or not an innovation is successful, the success or failure of an innovation ultimately lies with the leader. In this assignment, you will research and write abou..
Explain how leaders can leverage organizational capabilitie : Direction: Each question should contain word count of 200-250 words EACH (Question 1 and Question2). Please include referencesQ1) Based on research, explain how leaders can leverage organizational capabilities to create new demand and explore potenti..
How many backtracks occur : How many calls to isUnderAttack are there?
Write about dialogue, imagery, prose, setting, characters : Convince why your readers (a committee on college english education) why this particular author should continue to be included in a Brit Lit course such as ENG. Also include why this particular story is a great example on why British Literature i..
Compute required annual beginning-of-the-year lease payments : MB Leasing requires a 12 percent after-tax rate of return on this lease. Determine the required annual beginning-of-the-year lease payments.
Technique for creating behavior change in clients : One of the most important goals concerning a client's treatment in the Human Services profession is helping him or her to modify ineffective behaviors. There are many methods and techniques that a professional can use to achieve this goal. A profe..
What kind of healthcare institutions uses the two forms : What kind of healthcare institutions uses the two forms? Be specific and provide examples. How do the two forms differ? What types of patient information, codes, and insurance information are entered on each of the billing forms

Reviews

Write a Review

Mathematics Questions & Answers

  What is the probability of selecting an even numbered ball

Conditional Probability explained in this answer, A lotttery game has balls number 1 - 21. What is the probability of selecting an even numbered ball or a 10?

  Find the total distance traveled north

A plane travels 160 miles on a bearing of N 50° E and then changes its course to N 67° E and travels another 160 miles. Find the total distance traveled north and the total distance traveled east.

  Differential geometry-imbedded submanifold

Let phi : R^2 --> R be a function given by phi(x,y) = x^3 + xy + y^3 +1 For which points p =(0,0) , p=(1/3,1/3), p =(-1/3,-1/3) is the subset phi^-1 ( phi(p)) an imbedded sub-manifold of R^2.

  Find the x intercept of the tangent line

find the x intercept of the tangent line at x=-1

  Find the angle of inclination of the inclined plane

For a given velocity of projection from a point on the inclined plane, the maximum range down the plane is three times the maximum range up the incline. Then, find the angle of inclination of the inclined plane.

  What is the probability that she will pass all three tests

A medical screening program administers three independent physical fitness tests. Of the persons taking the test, 85% pass test I, 70% pass test II, and 50% pass test III. A participant is chosen at random.

  The fourth-degree polynomial

Evaluate a function on fixed-point iteration will converge to a positive solution of the equation.

  Determine how many barrels of oil are used

The amount of oil used by a ship traveling at a uniform speed varies jointly with the distance and the square of the speed. If the ship uses 200 barrels of oil in traveling 500 miles at 28 miles per hour, determine how many barrels of oil are used..

  Find the dimensions of the box

If an open box has a square base and a volume of 105 in.3 and is constructed from a tin sheet, find the dimensions of the box, assuming a minimum amount of material is used in its construction.

  Find the derivative of x32 using the definition of a

find the derivative of x32 using the definition of a derivative. you cannot use the power rule or any other

  Solve the congruence 2x 5 mod11 find f4 if f is defined

1.solve the congruence 2x 5 mod11a.5b.6c.7d.82.find f4 if f is defined recursively by f0 f1 1 and for n gt

  How many different such classes are possible

The dean decides the class should have 22 women and 15 men. How many possible classes are there now? Compare the number of possible classes to the solution to (a).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd