SlideShare a Scribd company logo
1 of 20
CROSSWORD PUZZLE
(USING BACKTRACKING)
NIT Surat
TEAM MEMBERS
Prince Nandha
Sakshi Jain
Lisa Verma
Himani Verma
PROBLEM STATEMENT
We are provided a crossword of 10*10 grid. The grid contains '+' or '-' as its cell values. Now, you are also
provided with a word list that needs to placed accurately in the grid. Cells marked with '-' are to be filled
with word list.
For example, The following is an example for the input crossword grid and the word list.
+ - + + + + + + + +
+ - + + + + + + + +
+ - + + + + + + + +
+ - - - - - + + + +
+ - + + + - + + + +
+ - + + + - + + + +
+ + + + + - + + + +
+ + - - - - - - + +
+ + + + + - + + + +
+ + + + + - + + + +
Words : { DELHI, ICELAND, ANKARA, LONDON }
Output for the given input should be:
+ L + + + + + + + +
+ O + + + + + + + +
+ N + + + + + + + +
+ D E L H I + + + +
+ O + + + C + + + +
+ N + + + E + + + +
+ + + + + L + + + +
+ + A N K A R A + +
+ + + + + N + + + +
+ + + + + D + + + +
Note: We have provided such test cases that there is only one solution for the given input.
Input format:
The first 10 lines of input contain crossword. Each of
10 lines has a character array of size 10. Input
characters are either '+' or '-'.
The next line of input contains the word list, in which
each word is separated by ';'.
Output format:
Print the crossword grid, after placing the words of
word list in '-' cells.
PSEUDO CODE
IMPLEMENTATION
public static void solveCr(char[][] crossword,ArrayList<String> words,int
index){
/* This prints the different ways crossword can be filled */
if (index==words.size()){
printC(crossword);
return;
}
String current = words.get(index);
for (int i = 0; i < crossword.length; i++) {
for (int j = 0; j < crossword.length; j++) {
if (crossword[i][j]=='-' || crossword[i][j]==current.charAt(0)){
if (canplaceH(crossword,current,i,j)==true){
boolean[] wePlaced = placeH(crossword,current,i,j); //Boolean array to use in
backtracking
solveCr(crossword,words,index+1); //Recursive call
unplaceH(crossword,wePlaced,i,j); //Backtracking
}
if (canplaceV(crossword,current,i,j)==true){
boolean[] wePlaced = placeV(crossword,current,i,j); //Boolean array to use in
backtracking
solveCr(crossword,words,index+1); //Recursive call
unplaceV(crossword,wePlaced,i,j); //Backtracking
}
}
}
}
/* This function checks if the word can be placed horizontally from index i,j */
public static boolean canplaceH(char[][] crossword,String current,int i,int j){
//First two if conditions make sure the assumed part of puzzle is bounded with + symbol
if (j-1>=0 && crossword[i][j-1]!='+') return false;
if (j+current.length()<crossword.length && crossword[i][j+current.length()]!='+')
return false;
for (int x = 0; x < current.length(); x++) {
if (x+j>=crossword.length) return false;
if (crossword[i][x+j]=='-' || crossword[i][x+j]==current.charAt(x)){
continue;
}else {
return false;
}
}
return true;
}
/* This function checks if the word can be vertically from index i,j */
public static boolean canplaceV(char[][] crossword,String current,int i,int j){
//First two if conditions make sure the assumed part of puzzle is bounded with + symbol
if (i-1>=0 && crossword[i-1][j]!='+') return false;
if (i+current.length()<crossword.length && crossword[i+current.length()][j]!='+')
return false;
for (int x = 0; x < current.length(); x++) {
if (x+i>=crossword.length) return false;
if (crossword[i+x][j]=='-' || crossword[i+x][j]==current.charAt(x)){
continue;
}else {
return false;
}
}
return true;
}
/* This function places the word horizontally from index i,j */
public static boolean[] placeH(char[][] crossword,String current,int i,int j){
boolean[] res=new boolean[current.length()];
for (int k = 0; k < current.length(); k++) {
if (crossword[i][j+k]=='-'){
res[k] = true;
crossword[i][j+k] = current.charAt(k);
}
else res[k] = false;
}
return res;
}
/* This function places the word vertically from index i,j */
public static boolean[] placeV(char[][] crossword,String current,int i,int j){
boolean[] res=new boolean[current.length()];
for (int k = 0; k < current.length(); k++) {
if (crossword[i+k][j]=='-'){
res[k] = true;
crossword[i+k][j] = current.charAt(k);
}
else res[k] = false;
}
return res;
}
/* This function is used to backtrack using the boolean array that was generated horizontally
*/
public static void unplaceH(char[][] crossword,boolean[] arr,int i,int j){
for (int k = 0; k < arr.length; k++) {
if (arr[k]){ //If boolean value is true then we replace the word with -
crossword[i][j+k]='-';
}
}
}
/* This function is used to backtrack using the boolean array that was generated vertically
*/
public static void unplaceV(char[][] crossword,boolean[] arr,int i,int j){
for (int k = 0; k < arr.length; k++) {
if (arr[k]){ //If boolean value is true then we replace the word with -
crossword[i+k][j]='-';
}
}
}
LETS THINK
ANALYSIS
O(N^2* K!)
Space Complexity : O(n^2 + k)
CONCLUSION
Hence we conclude that we successfully explained, implemented and analysed the
crossword puzzle algorithm using backtracking.
THANK YOU

More Related Content

What's hot

Methods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematicsMethods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematicsKaushal Patel
 
Teori Bilangan (Pembuktian Teorema Ucleid)
Teori Bilangan (Pembuktian Teorema Ucleid)Teori Bilangan (Pembuktian Teorema Ucleid)
Teori Bilangan (Pembuktian Teorema Ucleid)Erik Kuswanto
 
Persoalan interpolasi Polinom
Persoalan interpolasi PolinomPersoalan interpolasi Polinom
Persoalan interpolasi Polinomsur kuati
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errorsmaheej
 
Koordinat kartesius (geometri analitik ruang)
Koordinat kartesius (geometri analitik ruang)Koordinat kartesius (geometri analitik ruang)
Koordinat kartesius (geometri analitik ruang)ShellaSavitri
 
Transformasi linear
Transformasi linear Transformasi linear
Transformasi linear unna_ahmad
 
CONTOH DISERTASI METODE SEM
CONTOH DISERTASI METODE SEM CONTOH DISERTASI METODE SEM
CONTOH DISERTASI METODE SEM EDI RIADI
 
Laplace Transform of Periodic Function
Laplace Transform of Periodic FunctionLaplace Transform of Periodic Function
Laplace Transform of Periodic FunctionDhaval Shukla
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)KALAISELVI P
 
Induksi matematika kls xii
Induksi matematika kls xiiInduksi matematika kls xii
Induksi matematika kls xiiMedi Harja
 
16 rpp-persamaan-kuadrat
16 rpp-persamaan-kuadrat16 rpp-persamaan-kuadrat
16 rpp-persamaan-kuadratAyu Varadita
 
Metode VAM Kelompok 2 program linear.pdf
Metode VAM Kelompok 2 program linear.pdfMetode VAM Kelompok 2 program linear.pdf
Metode VAM Kelompok 2 program linear.pdfArulJak
 
Sistem aksioma dan model
Sistem aksioma dan modelSistem aksioma dan model
Sistem aksioma dan modelStepanyCristy
 
ANALISIS RIIL 1 2.5 ROBERT G BARTLE
ANALISIS RIIL 1 2.5 ROBERT G BARTLEANALISIS RIIL 1 2.5 ROBERT G BARTLE
ANALISIS RIIL 1 2.5 ROBERT G BARTLEMuhammad Nur Chalim
 

What's hot (20)

Methods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematicsMethods of variation of parameters- advance engineering mathe mathematics
Methods of variation of parameters- advance engineering mathe mathematics
 
Teori Bilangan (Pembuktian Teorema Ucleid)
Teori Bilangan (Pembuktian Teorema Ucleid)Teori Bilangan (Pembuktian Teorema Ucleid)
Teori Bilangan (Pembuktian Teorema Ucleid)
 
Persoalan interpolasi Polinom
Persoalan interpolasi PolinomPersoalan interpolasi Polinom
Persoalan interpolasi Polinom
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
 
Koordinat kartesius (geometri analitik ruang)
Koordinat kartesius (geometri analitik ruang)Koordinat kartesius (geometri analitik ruang)
Koordinat kartesius (geometri analitik ruang)
 
Transformasi linear
Transformasi linear Transformasi linear
Transformasi linear
 
CONTOH DISERTASI METODE SEM
CONTOH DISERTASI METODE SEM CONTOH DISERTASI METODE SEM
CONTOH DISERTASI METODE SEM
 
Laplace Transform of Periodic Function
Laplace Transform of Periodic FunctionLaplace Transform of Periodic Function
Laplace Transform of Periodic Function
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
 
Induksi matematika kls xii
Induksi matematika kls xiiInduksi matematika kls xii
Induksi matematika kls xii
 
16 rpp-persamaan-kuadrat
16 rpp-persamaan-kuadrat16 rpp-persamaan-kuadrat
16 rpp-persamaan-kuadrat
 
Metode VAM Kelompok 2 program linear.pdf
Metode VAM Kelompok 2 program linear.pdfMetode VAM Kelompok 2 program linear.pdf
Metode VAM Kelompok 2 program linear.pdf
 
Basis dan Dimensi
Basis dan DimensiBasis dan Dimensi
Basis dan Dimensi
 
Modul Kalkulus
Modul KalkulusModul Kalkulus
Modul Kalkulus
 
geometri terurut
geometri terurutgeometri terurut
geometri terurut
 
Turunan numerik
Turunan numerikTurunan numerik
Turunan numerik
 
Sistem aksioma dan model
Sistem aksioma dan modelSistem aksioma dan model
Sistem aksioma dan model
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
ANALISIS RIIL 1 2.5 ROBERT G BARTLE
ANALISIS RIIL 1 2.5 ROBERT G BARTLEANALISIS RIIL 1 2.5 ROBERT G BARTLE
ANALISIS RIIL 1 2.5 ROBERT G BARTLE
 
Analytic function
Analytic functionAnalytic function
Analytic function
 

Similar to Crossword puzzle Using Backtracking in Java

Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdfC# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdffazalenterprises
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Dr. Volkan OBAN
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and testsintive
 
The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212Mahmoud Samir Fayed
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++Vikash Dhal
 
Structured data type
Structured data typeStructured data type
Structured data typeOmkar Majukar
 
Data structure
Data structureData structure
Data structureMarkustec
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overviewAveic
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Chapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).pptChapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).ppthenokmetaferia1
 

Similar to Crossword puzzle Using Backtracking in Java (20)

Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdfC# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Coding
CodingCoding
Coding
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
lecture5.ppt
lecture5.pptlecture5.ppt
lecture5.ppt
 
Structured data type
Structured data typeStructured data type
Structured data type
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Arrays
ArraysArrays
Arrays
 
Data structure
Data structureData structure
Data structure
 
Postgresql 9.3 overview
Postgresql 9.3 overviewPostgresql 9.3 overview
Postgresql 9.3 overview
 
Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Chapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).pptChapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).ppt
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 

Crossword puzzle Using Backtracking in Java

  • 2. TEAM MEMBERS Prince Nandha Sakshi Jain Lisa Verma Himani Verma
  • 3. PROBLEM STATEMENT We are provided a crossword of 10*10 grid. The grid contains '+' or '-' as its cell values. Now, you are also provided with a word list that needs to placed accurately in the grid. Cells marked with '-' are to be filled with word list. For example, The following is an example for the input crossword grid and the word list. + - + + + + + + + + + - + + + + + + + + + - + + + + + + + + + - - - - - + + + + + - + + + - + + + + + - + + + - + + + + + + + + + - + + + + + + - - - - - - + + + + + + + - + + + + + + + + + - + + + + Words : { DELHI, ICELAND, ANKARA, LONDON }
  • 4. Output for the given input should be: + L + + + + + + + + + O + + + + + + + + + N + + + + + + + + + D E L H I + + + + + O + + + C + + + + + N + + + E + + + + + + + + + L + + + + + + A N K A R A + + + + + + + N + + + + + + + + + D + + + + Note: We have provided such test cases that there is only one solution for the given input.
  • 5. Input format: The first 10 lines of input contain crossword. Each of 10 lines has a character array of size 10. Input characters are either '+' or '-'. The next line of input contains the word list, in which each word is separated by ';'. Output format: Print the crossword grid, after placing the words of word list in '-' cells.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. IMPLEMENTATION public static void solveCr(char[][] crossword,ArrayList<String> words,int index){ /* This prints the different ways crossword can be filled */ if (index==words.size()){ printC(crossword); return; } String current = words.get(index);
  • 12. for (int i = 0; i < crossword.length; i++) { for (int j = 0; j < crossword.length; j++) { if (crossword[i][j]=='-' || crossword[i][j]==current.charAt(0)){ if (canplaceH(crossword,current,i,j)==true){ boolean[] wePlaced = placeH(crossword,current,i,j); //Boolean array to use in backtracking solveCr(crossword,words,index+1); //Recursive call unplaceH(crossword,wePlaced,i,j); //Backtracking } if (canplaceV(crossword,current,i,j)==true){ boolean[] wePlaced = placeV(crossword,current,i,j); //Boolean array to use in backtracking solveCr(crossword,words,index+1); //Recursive call unplaceV(crossword,wePlaced,i,j); //Backtracking } } } }
  • 13. /* This function checks if the word can be placed horizontally from index i,j */ public static boolean canplaceH(char[][] crossword,String current,int i,int j){ //First two if conditions make sure the assumed part of puzzle is bounded with + symbol if (j-1>=0 && crossword[i][j-1]!='+') return false; if (j+current.length()<crossword.length && crossword[i][j+current.length()]!='+') return false; for (int x = 0; x < current.length(); x++) { if (x+j>=crossword.length) return false; if (crossword[i][x+j]=='-' || crossword[i][x+j]==current.charAt(x)){ continue; }else { return false; } } return true; }
  • 14. /* This function checks if the word can be vertically from index i,j */ public static boolean canplaceV(char[][] crossword,String current,int i,int j){ //First two if conditions make sure the assumed part of puzzle is bounded with + symbol if (i-1>=0 && crossword[i-1][j]!='+') return false; if (i+current.length()<crossword.length && crossword[i+current.length()][j]!='+') return false; for (int x = 0; x < current.length(); x++) { if (x+i>=crossword.length) return false; if (crossword[i+x][j]=='-' || crossword[i+x][j]==current.charAt(x)){ continue; }else { return false; } } return true; }
  • 15. /* This function places the word horizontally from index i,j */ public static boolean[] placeH(char[][] crossword,String current,int i,int j){ boolean[] res=new boolean[current.length()]; for (int k = 0; k < current.length(); k++) { if (crossword[i][j+k]=='-'){ res[k] = true; crossword[i][j+k] = current.charAt(k); } else res[k] = false; } return res; } /* This function places the word vertically from index i,j */ public static boolean[] placeV(char[][] crossword,String current,int i,int j){ boolean[] res=new boolean[current.length()]; for (int k = 0; k < current.length(); k++) { if (crossword[i+k][j]=='-'){ res[k] = true; crossword[i+k][j] = current.charAt(k); } else res[k] = false; } return res; }
  • 16. /* This function is used to backtrack using the boolean array that was generated horizontally */ public static void unplaceH(char[][] crossword,boolean[] arr,int i,int j){ for (int k = 0; k < arr.length; k++) { if (arr[k]){ //If boolean value is true then we replace the word with - crossword[i][j+k]='-'; } } } /* This function is used to backtrack using the boolean array that was generated vertically */ public static void unplaceV(char[][] crossword,boolean[] arr,int i,int j){ for (int k = 0; k < arr.length; k++) { if (arr[k]){ //If boolean value is true then we replace the word with - crossword[i+k][j]='-'; } } }
  • 19. CONCLUSION Hence we conclude that we successfully explained, implemented and analysed the crossword puzzle algorithm using backtracking.