Tuesday, May 23, 2017

Leetcode 37: Sudoku Solver

May 23, 2017


Sudoku solver is the most classical algorithm to apply Depth First Search (DFS) using recursion and also use back tracking as well. Julia had a very good experience in May 22, 2017, she had chance to learn to write a short version of depth first search coached by her mocking peer.

Most important design is about base case. To make the implementation as simple as possible, DFS algorithm can start from the matrix left top corner, and then scan from left to right, top to bottom, if the row is bigger than 8, then it finds a solution.

Algorithm Study 

Problem statement is here.

The C# code practice is here.

Algorithm talk 

May 25, 2017

It is also very good experience to use Sudoku Solver algorithm to conduct mocking experience. Julia did her first mocking experience using the algorithm as an interviewer.

June 13, 2017

It is very good experience to write sudoku in mocking experience, this is the third time Julia worked on Sudoku for mocking experience.

Julia put the code into Visual Studio to compile and here is her C# practice code.

Here are two mistakes in writing through mocking experience:

One compiler error in mocking writing, line 61,
add type conversion by adding (char), and also (number + '0')

line 61  board[row, col] = (char)(number + '0'); // add '0'

One compiler error, duplicate variable inside for loop on line 82, change col to column; line 91, row is changed to rowIndex.

Try to pass online judge, and then find the bug on line 84, 93, 111. C# code is here.

line 84 if (board[row, column] - number == '0') // should be '0', not 0

Actionable Item

Julia still remembered that she got some great advice on her second mocking experience using Sudoku, and then she was coached by the peer to use DFS starting from (0, 0) and set the base case to row > 8.

No comments:

Post a Comment