SlideShare a Scribd company logo
1 of 2
Download to read offline
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.docxannetnash8266
 
#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).docxPiersRCoThomsonw
 
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.pdffeelinggifts
 
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.pdfkokah57440
 
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.pdffazilfootsteps
 
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.docxKomlin1
 
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.pdfarchanaemporium
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding classJonah Marrs
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascriptReece 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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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 .pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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 .pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 
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.pdfADITIEYEWEAR
 

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

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

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"); } } }