SlideShare a Scribd company logo
import java.util.LinkedList; import java.util.Queue; import java.util.Stack; class
Sudoku_Solver_question { public static int type = 0; public static int height = 0; // Node exploration
holds the sudoku board in every iteration private static class Exploration { char[][] board; int curCell
= 0; // constructor method public Exploration(char[][] board, int curCell) { this.board =
cloneBoard(board); this.curCell = curCell; } // clones the board for every state private char[][]
cloneBoard(char[][] board) { char[][] newBoard = new char[board.length][board[0].length];
copyIntoBoard(board, newBoard); return newBoard; } } public static boolean BFS(char[][] board) {
// TODO write BFS search algorithm } public static boolean DFS(char[][] board) { // TODO write
DFS search algorithm } /** * parameter: index * return: index * Returns the index of a row based on
type(6x6 / 9x9) of the board */ private static int getRowForIndex(int idx) { return idx / type; } /** *
parameter: index * return: index * Returns the index of a column based on type(6x6 / 9x9) of the
board */ private static int getColumnForIndex(int idx) { return idx % type; } /** * Parameters: source
board & destination board * return: null * Copies the source board to destination board in every
state */ protected static void copyIntoBoard(char[][] src, char[][] dst) { for (int i = 0; i < src.length;
i++) { System.arraycopy(src[i], 0, dst[i], 0, src[i].length); } } /** * Parameters: Board & box index
number * returns: true / false * Validates the box, returns true if there is no duplicate number in the
box else false */ private static boolean isValidSquare(char[][] board, int s) { boolean[] isPresent =
new boolean[board.length+1]; for (int r = (s / 3) * height; r < ((s / 3) + 1) * height; r++) { for (int c =
(s % 3) * height; c < ((s % 3) + 1) * height; c++) { char value = board[r][c]; if (value == '.') {
continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; }
isPresent[intVal] = true; } } return true; } /** * Parameters: Board & column index number * returns:
true / false * Validates the box, returns true if there is no duplicate number in the column else false
*/ private static boolean isValidColumn(char[][] board, int c) { boolean[] isPresent = new
boolean[board.length+1]; for (int i = 0; i < board.length; i++) { char value = board[i][c]; if (value ==
'.') { continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; }
isPresent[intVal] = true; } return true; } /** * Parameters: Board & row index number * returns: true /
false * Validates the box, returns true if there is no duplicate number in the row else false */ private
static boolean isValidRow(char[][] board, int r) { boolean[] isPresent = new
boolean[board.length+1]; for (int i = 0; i < board.length; i++) { char value = board[r][i]; if (value ==
'.') { continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; }
isPresent[intVal] = true; } return true; } /** * parameter: board * return: null * prints the board/matrix
in the console */ public static void print_matrix(char[][] board){ int type = board.length; for(int i = 0;
i<type;i++){ for(int j=0;j<type;j++){ System.out.print(board[i][j]+" "); } System.out.println(" "); } } /** *
Start of the program main function */ public static void main(String args[]){ // 6x6 sudoku board
char[][] board_6x6 = {{'.','.','.','.','4','.'}, {'5','6','.','.','.','.'}, {'3','.','2','6','5','4'}, {'.','4','.','2','.','3'},
{'4','.','.','.','6','5'}, {'1','5','6','.','.','.'}}; // type holds the length of the board type = board_6x6.length; //
height holds the height of each box in the board height = board_6x6.length/3; // prints the problem
board System.out.println("Problem board is: "); print_matrix(board_6x6); // Solve the problem
board using BFS boolean status = BFS(board_6x6); // based on the status print the solution
if(status){ System.out.println("n BFS - Solution board is: "); print_matrix(board_6x6); }else{
System.out.println("n BFS - No Solution found"); } // solve the problem using DFS status =
DFS(board_6x6); // based on the status print the solution if(status){ System.out.println("n DFS -
Solution board is: "); print_matrix(board_6x6); }else{ System.out.println("n DFS - No Solution
found"); } char[][] board_9x9 = {{'.','.','.','8','4','.','6','5','.'}, {'.','8','.','.','.','.','.','.','9'},
{'.','.','.','.','.','5','2','.','1'}, {'.','3','4','.','7','.','5','.','6'}, {'.','6','.','2','5','1','.','3','.'}, {'5','.','9','.','6','.','7','2','.'},
{'1','.','8','5','.','.','.','.','.'}, {'6','.','.','.','.','.','.','4','.'}, {'.','5','2','.','8','6','.','.','.'}}; // type holds the length of
the board type = board_9x9.length; // height holds the height of each box in the board height =
board_9x9.length/3; // prints the problem board System.out.println("Problem board is: ");
print_matrix(board_9x9); // Solve the problem board using BFS boolean status1 =
BFS(board_9x9); // based on the status print the solution if(status1){ System.out.println("n BFS -
Solution board is: "); print_matrix(board_9x9); }else{ System.out.println("n BFS - No Solution
found"); } // Solve the problem board using DFS status1 = DFS(board_9x9); // based on the status
print the solution if(status1){ System.out.println("n DFS - Solution board is: ");
print_matrix(board_9x9); }else{ System.out.println("n DFS - No Solution found"); } } }

More Related Content

Similar to import javautilLinkedList import javautilQueue import .pdf

write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
annetnash8266
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
PiersRCoThomsonw
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
hurairawarisarain23
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
feelinggifts
 
C++ Language
C++ LanguageC++ Language
C++ Language
Vidyacenter
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
kokah57440
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
fazilfootsteps
 
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 TilePUzzle class Anderson, Franceschi public class TilePu.docx TilePUzzle class Anderson, Franceschi public class TilePu.docx
TilePUzzle class Anderson, Franceschi public class TilePu.docx
Komlin1
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
Jonah Marrs
 
Opp compile
Opp compileOpp compile
Opp compile
Muhammad Faiz
 
Virtual inheritance
Virtual inheritanceVirtual inheritance
Virtual inheritance
Rajendran Praj
 
C program
C programC program
C program
Komal Singh
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
Reece Carlson
 

Similar to import javautilLinkedList import javautilQueue import .pdf (15)

write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
java slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdfjava slip for bachelors of business administration.pdf
java slip for bachelors of business administration.pdf
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
 
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 TilePUzzle class Anderson, Franceschi public class TilePu.docx TilePUzzle class Anderson, Franceschi public class TilePu.docx
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
 
Opp compile
Opp compileOpp compile
Opp compile
 
Virtual inheritance
Virtual inheritanceVirtual inheritance
Virtual inheritance
 
C program
C programC program
C program
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 

More from ADITIEYEWEAR

In a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdfIn a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdf
ADITIEYEWEAR
 
In a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdfIn a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdf
ADITIEYEWEAR
 
In a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdfIn a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdf
ADITIEYEWEAR
 
In a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdfIn a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdf
ADITIEYEWEAR
 
In a recent poll the Gallup Organization found that 45 of.pdf
In a recent poll the Gallup Organization found  that 45 of.pdfIn a recent poll the Gallup Organization found  that 45 of.pdf
In a recent poll the Gallup Organization found that 45 of.pdf
ADITIEYEWEAR
 
In a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdfIn a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdf
ADITIEYEWEAR
 
In a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdfIn a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdf
ADITIEYEWEAR
 
In a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdfIn a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdf
ADITIEYEWEAR
 
In a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdfIn a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdf
ADITIEYEWEAR
 
In 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdfIn 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdf
ADITIEYEWEAR
 
In a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdfIn a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdf
ADITIEYEWEAR
 
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdfin 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
ADITIEYEWEAR
 
In a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdfIn a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdf
ADITIEYEWEAR
 
In a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdfIn a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdf
ADITIEYEWEAR
 
In 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdfIn 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdf
ADITIEYEWEAR
 
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdfIn 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
ADITIEYEWEAR
 
In 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdfIn 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdf
ADITIEYEWEAR
 
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdfimport yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
ADITIEYEWEAR
 
In 2020 Natural Selection a nationwide computer dating se.pdf
In 2020 Natural Selection a  nationwide computer dating se.pdfIn 2020 Natural Selection a  nationwide computer dating se.pdf
In 2020 Natural Selection a nationwide computer dating se.pdf
ADITIEYEWEAR
 
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdfIn 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
ADITIEYEWEAR
 

More from ADITIEYEWEAR (20)

In a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdfIn a study on the retirement savings plans of young Canadian.pdf
In a study on the retirement savings plans of young Canadian.pdf
 
In a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdfIn a spreadsheet decompose the change in the debt ratio fro.pdf
In a spreadsheet decompose the change in the debt ratio fro.pdf
 
In a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdfIn a school there are 5 sections of 10th standard with same.pdf
In a school there are 5 sections of 10th standard with same.pdf
 
In a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdfIn a recent year grade 10 Washington State public school st.pdf
In a recent year grade 10 Washington State public school st.pdf
 
In a recent poll the Gallup Organization found that 45 of.pdf
In a recent poll the Gallup Organization found  that 45 of.pdfIn a recent poll the Gallup Organization found  that 45 of.pdf
In a recent poll the Gallup Organization found that 45 of.pdf
 
In a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdfIn a random sample of UTC students 50 indicated they are b.pdf
In a random sample of UTC students 50 indicated they are b.pdf
 
In a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdfIn a previous yeac the weights of the members of the San Fra.pdf
In a previous yeac the weights of the members of the San Fra.pdf
 
In a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdfIn a questionnaire for 100 pernens the gender distribution .pdf
In a questionnaire for 100 pernens the gender distribution .pdf
 
In a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdfIn a normal distribution what is the probability that a ran.pdf
In a normal distribution what is the probability that a ran.pdf
 
In 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdfIn 2019 scientists conducted a research study about spicy f.pdf
In 2019 scientists conducted a research study about spicy f.pdf
 
In a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdfIn a holiday gathering two families family 1 and family 2 .pdf
In a holiday gathering two families family 1 and family 2 .pdf
 
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdfin 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
in 2019 facebook Announced is Plan 70 pon out a nea stablec.pdf
 
In a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdfIn a city of half a million there are initially 400 cases o.pdf
In a city of half a million there are initially 400 cases o.pdf
 
In a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdfIn a 10year graph with an explanation of Idaho Panhandle H.pdf
In a 10year graph with an explanation of Idaho Panhandle H.pdf
 
In 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdfIn 2D let xx1x2 Write down the explicit cubic feature.pdf
In 2D let xx1x2 Write down the explicit cubic feature.pdf
 
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdfIn 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
In 2018 Tirana Trucks had a retum on equity of 180 and a.pdf
 
In 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdfIn 2021 California passed a law to provide all public schoo.pdf
In 2021 California passed a law to provide all public schoo.pdf
 
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdfimport yfinance as yf yfTickerstickersAAPL TSLA.pdf
import yfinance as yf yfTickerstickersAAPL TSLA.pdf
 
In 2020 Natural Selection a nationwide computer dating se.pdf
In 2020 Natural Selection a  nationwide computer dating se.pdfIn 2020 Natural Selection a  nationwide computer dating se.pdf
In 2020 Natural Selection a nationwide computer dating se.pdf
 
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdfIn 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
In 2017 Americans spent a recordhigh 91 billion on Hallo.pdf
 

Recently uploaded

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
IsmaelVazquez38
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
blueshagoo1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 

Recently uploaded (20)

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 

import javautilLinkedList import javautilQueue import .pdf

  • 1. import java.util.LinkedList; import java.util.Queue; import java.util.Stack; class Sudoku_Solver_question { public static int type = 0; public static int height = 0; // Node exploration holds the sudoku board in every iteration private static class Exploration { char[][] board; int curCell = 0; // constructor method public Exploration(char[][] board, int curCell) { this.board = cloneBoard(board); this.curCell = curCell; } // clones the board for every state private char[][] cloneBoard(char[][] board) { char[][] newBoard = new char[board.length][board[0].length]; copyIntoBoard(board, newBoard); return newBoard; } } public static boolean BFS(char[][] board) { // TODO write BFS search algorithm } public static boolean DFS(char[][] board) { // TODO write DFS search algorithm } /** * parameter: index * return: index * Returns the index of a row based on type(6x6 / 9x9) of the board */ private static int getRowForIndex(int idx) { return idx / type; } /** * parameter: index * return: index * Returns the index of a column based on type(6x6 / 9x9) of the board */ private static int getColumnForIndex(int idx) { return idx % type; } /** * Parameters: source board & destination board * return: null * Copies the source board to destination board in every state */ protected static void copyIntoBoard(char[][] src, char[][] dst) { for (int i = 0; i < src.length; i++) { System.arraycopy(src[i], 0, dst[i], 0, src[i].length); } } /** * Parameters: Board & box index number * returns: true / false * Validates the box, returns true if there is no duplicate number in the box else false */ private static boolean isValidSquare(char[][] board, int s) { boolean[] isPresent = new boolean[board.length+1]; for (int r = (s / 3) * height; r < ((s / 3) + 1) * height; r++) { for (int c = (s % 3) * height; c < ((s % 3) + 1) * height; c++) { char value = board[r][c]; if (value == '.') { continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; } isPresent[intVal] = true; } } return true; } /** * Parameters: Board & column index number * returns: true / false * Validates the box, returns true if there is no duplicate number in the column else false */ private static boolean isValidColumn(char[][] board, int c) { boolean[] isPresent = new boolean[board.length+1]; for (int i = 0; i < board.length; i++) { char value = board[i][c]; if (value == '.') { continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; } isPresent[intVal] = true; } return true; } /** * Parameters: Board & row index number * returns: true / false * Validates the box, returns true if there is no duplicate number in the row else false */ private static boolean isValidRow(char[][] board, int r) { boolean[] isPresent = new boolean[board.length+1]; for (int i = 0; i < board.length; i++) { char value = board[r][i]; if (value == '.') { continue; } int intVal = Character.getNumericValue(value); if (isPresent[intVal]) { return false; } isPresent[intVal] = true; } return true; } /** * parameter: board * return: null * prints the board/matrix in the console */ public static void print_matrix(char[][] board){ int type = board.length; for(int i = 0; i<type;i++){ for(int j=0;j<type;j++){ System.out.print(board[i][j]+" "); } System.out.println(" "); } } /** * Start of the program main function */ public static void main(String args[]){ // 6x6 sudoku board char[][] board_6x6 = {{'.','.','.','.','4','.'}, {'5','6','.','.','.','.'}, {'3','.','2','6','5','4'}, {'.','4','.','2','.','3'}, {'4','.','.','.','6','5'}, {'1','5','6','.','.','.'}}; // type holds the length of the board type = board_6x6.length; // height holds the height of each box in the board height = board_6x6.length/3; // prints the problem board System.out.println("Problem board is: "); print_matrix(board_6x6); // Solve the problem board using BFS boolean status = BFS(board_6x6); // based on the status print the solution if(status){ System.out.println("n BFS - Solution board is: "); print_matrix(board_6x6); }else{ System.out.println("n BFS - No Solution found"); } // solve the problem using DFS status = DFS(board_6x6); // based on the status print the solution if(status){ System.out.println("n DFS -
  • 2. Solution board is: "); print_matrix(board_6x6); }else{ System.out.println("n DFS - No Solution found"); } char[][] board_9x9 = {{'.','.','.','8','4','.','6','5','.'}, {'.','8','.','.','.','.','.','.','9'}, {'.','.','.','.','.','5','2','.','1'}, {'.','3','4','.','7','.','5','.','6'}, {'.','6','.','2','5','1','.','3','.'}, {'5','.','9','.','6','.','7','2','.'}, {'1','.','8','5','.','.','.','.','.'}, {'6','.','.','.','.','.','.','4','.'}, {'.','5','2','.','8','6','.','.','.'}}; // type holds the length of the board type = board_9x9.length; // height holds the height of each box in the board height = board_9x9.length/3; // prints the problem board System.out.println("Problem board is: "); print_matrix(board_9x9); // Solve the problem board using BFS boolean status1 = BFS(board_9x9); // based on the status print the solution if(status1){ System.out.println("n BFS - Solution board is: "); print_matrix(board_9x9); }else{ System.out.println("n BFS - No Solution found"); } // Solve the problem board using DFS status1 = DFS(board_9x9); // based on the status print the solution if(status1){ System.out.println("n DFS - Solution board is: "); print_matrix(board_9x9); }else{ System.out.println("n DFS - No Solution found"); } } }