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

  Are closures and interiors of connected sets connected

Are closures and interiors of connected sets always connected? (Look at subsets of R2).

  Suppose that entrance exam test scores are normally

the table below shows the raw score for reading comprehension on a college entrance exam for 7 randomly selected male

  What is the planning value for the population

What is the planning value for the population standard deviation and how large a sample should be taken if the desired margin of error is as shown below (to the nearest whole number)?

  Determine the mass of a wire formed by the intersection of

find the mass of a wire formed by the intersection of the sphere x2 y2 z2 1 and the plane x z0 if the density of a

  Systems of linear equations with three variables

Please solve for x, y & z using the process of elimination method (non matrix method)

  Equal probability of being chosen

There are 12 light bulbs, 5 of which are defective. All bulbs look alike and have an equal probability of being chosen. Three light bulbs are selected and placed on the table.

  Determining vector-gradient

The temperature of a plate at the point (x,y) is given by T(x,y) = 300+ 3x^2 -2y^2. A heat hating ant is located at the point (3,2).

  What is probability that component was made in buffalo

Find the range, mean, median, and mode of the dataset - what proportion of the data is within 1 standard deviation of the sample mean - What is the probability that you will get a sum of 27 at leasttwice?

  Simple linear regression equation

Simple linear regression equation

  Find the supremum and infimum

Find the supremum (least upper bound), infimum (greatest lower bound), maximum and minimum of the following sets, if they exist and find the real numbers x that satisfy the given conditions.

  The equation of the hyperbola at the origin

The number of moose in northern Maine is increasing at a rate of 3% per year. It is estimated in one county that there are now 2000 moose. If the growth rate remains unchanged, how many years will it be until there are 2600 moose in that county?

  Altitude in equilateral triangle

Construct an equilateral triangle. Then construct one of its altitudes. If the sides each have length 1, how long is the altitude

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