Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / study / engineering / computer science / computer science questions and a

ID: 3597581 • Letter: H

Question

home / study / engineering / computer science / computer science questions and answers / consider the (decimal) languages defined below. for each one, either give a regular expression ...

Your question has been posted.

We'll notify you when a Chegg Expert has answered. Post another question.

Question: Consider the (decimal) languages defined below. For each one, either give a regular expression fo...

Consider the (decimal) languages defined below. For each one, either give a regular expression for its elements or prove the language is non-regular:

In all examples, a number cannot start with a 0 (unless it is 0 itself):
e) Le = { w | as an integer w is such that the sum of its digits is a multiple of 2 }.
f) Lf = { w | as an integer w is a power of 2 }.
g) Lg = { w | as an integer } (with SUM = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -}).
h) Lh = { w | w is the decimal representation of a rational number}. (with SUM = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -, ., [,]}) Examples of such strings are 0.[3] representing the number 0.3333...=1/3 and -23.15[24] representing the number -23.152424242424...=-76403/3300.

Explanation / Answer

// square per roll or column

Public static final int BOARD_SIZE=8;

//used to indicate an empty square

Public static final int EMPTY=0;

Public static final int QUEEN=1;

Private int board [][]; //chess board

Public Queens (){

//--------------------------------------------

//Constructor : Creates and empty board.

//---------------------------------------------

board = new int [BOARD_SIZE] [BOARD_SIZE];

}//end constructor

Public void clearBoard(){

//---------------------------------------------------------

//Clears the board.

//precondition: none

//postcondition: sets all squares to EMPTY.

//---------------------------------------------------------

//to be implemented in programming problem 1

}// end constructor

Public void displayBoard(){

//---------------------------------------------------------------

//Displays the board

//precondition: none.

//postcondition: Board is written to standard

//output; zero is an empty square,one is a square

//containing a queen (QUEEN).

//----------------------------------------------------------

To implement programming problem 1

}//end displayBoard

Public boolean placeQueens(int column){

//------------------------------------------------------------------

//places queens in columns of the board beginning

//at the column specified

//preconditions : Queen are placed correctly

//in columns 1 through column -1.

//postcondition; if a solution is found ,each

//column of the board contains one queen and method

//return true; otherwise ,return false (no

//solutionexists for a queen anywhere in column

//specified

//------------------------------------------------------------------

If (column > BOARD_SIZE){

return true ; //base case

}

else{

boolean queenPlaced=false;

int row =1;// number of square in column

while(!queenPlaced && (row <=BOARD_SIZE){

//if square can be attacked

If (isUnderatttack(row,column)){

++row //consider next square in column

}//end if

else{//place queen and consider next column

setQueen(row,column);

queenPlaced= placeQueens(column+1);

//if no queen is possible in next column,

If (!queenPlaced){

//backtrack: remove queen placedearlier

//and try next square in column

removeQueen (row, column );

++row;

}//end if

}//end if

}//end while

return queenPlaced;

}//end if

}// end PlaceQueens

Private Void setQueens(int row,int column){

//--------------------------------------------------------------------

Sets a queen at square indicated by rowand column

//precondition:none

//postcondition: sets the square on the board in a given row and column.

//----------------------------------------------

//to implement be implemented in programming problem 1

}//end removeQueens

private boolean isUnderAtttack (int row ,itn column){

//---------------------------------------------------------------------

//determine whether the square on the board at a

//given row or column is underAttackby any queens

//in the columns 1 through coulumn-1.

Precondition. Each column between 1 and coulumn -1

//has a queen placed in a square at a specific row

//none of these queens can be attacked by any other queen

Post condition; if the designated square is under attack

//return true; otherwise,return false.

//---------------------------------------------------------

To implement programming problem 1

}// end isUnderAttack

Private in index(int number ){

//---------------------------------------------------

Returns the array index that correspond to

//a row or column number

//precondition ; 1<= number <=BOARD_SIZE.

//post condition ; returns adjusted index value.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote