Please draw a UML class diagram for the following code:     public class SudokuSolver {       public static boolean solveSudoku(int[][] board) {         int N = board.length;         int[] emptyCell = findEmptyCell(board);                  if (emptyCell == null) {            return true;        }                int row = emptyCell[0];        int col = emptyCell[1];                for (int num = 1; num <= 9; num++) {            if (isValidMove(board, row, col, num)) {                board[row][col] = num;                                if (solveSudoku(board)) {                    return true;                }                                board[row][col] = 0;            }        }                return false;    }        public static int[] findEmptyCell(int[][] board) {        int N = board.length;        for (int row = 0; row < N; row++) {            for (int col = 0; col < N; col++) {                if (board[row][col] == 0) {                    return new int[]{row, col};                }            }        }        return null;    }        public static boolean isValidMove(int[][] board, int row, int col, int num) {        return isValidRow(board, row, num) &&               isValidCol(board, col, num) &&               isValidRegion(board, row - row % 3, col - col % 3, num);    }        public static boolean isValidRow(int[][] board, int row, int num) {        for (int col = 0; col < board.length; col++) {            if (board[row][col] == num) {                return false;            }        }        return true;    }        public static boolean isValidCol(int[][] board, int col, int num) {        for (int row = 0; row < board.length; row++) {            if (board[row][col] == num) {                return false;            }        }        return true;    }        public static boolean isValidRegion(int[][] board, int startRow, int startCol, int num) {        for (int row = 0; row < 3; row++) {            for (int col = 0; col < 3; col++) {                if (board[row + startRow][col + startCol] == num) {                    return false;                }            }        }        return true;    }        public static void printBoard(int[][] board) {        int N = board.length;        for (int row = 0; row < N; row++) {            for (int col = 0; col < N; col++) {                System.out.print(board[row][col] + " ");            }            System.out.println();        }    }        public static void main(String[] args) {        int[][] puzzle = {            {0, 0, 3, 0, 0, 8, 0, 2, 0},            {6, 0, 0, 3, 0, 0, 0, 0, 9},            {0, 9, 0, 7, 0, 0, 1, 0, 4},            {9, 0, 0, 2, 0, 0, 5, 4, 3},            {0, 8, 0, 4, 0, 1, 0, 0, 0},            {4, 6, 2, 0, 0, 7, 0, 0, 1},            {1, 0, 6, 0, 0, 3, 0, 9, 0},            {8, 0, 0, 0, 0, 9, 3, 0, 6},            {0, 3, 0, 6, 0, 0, 7, 0, 0}        };                if (solveSudoku(puzzle)) {            printBoard(puzzle);        } else {            System.out.println("No solution exists.");        }    } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please draw a UML class diagram for the following code:

 

 

public class SudokuSolver {

 

    public static boolean solveSudoku(int[][] board) {

        int N = board.length;

        int[] emptyCell = findEmptyCell(board);

        

        if (emptyCell == null) {

           return true;

       }

       

       int row = emptyCell[0];

       int col = emptyCell[1];

       

       for (int num = 1; num <= 9; num++) {

           if (isValidMove(board, row, col, num)) {

               board[row][col] = num;

               

               if (solveSudoku(board)) {

                   return true;

               }

               

               board[row][col] = 0;

           }

       }

       

       return false;

   }

   

   public static int[] findEmptyCell(int[][] board) {

       int N = board.length;

       for (int row = 0; row < N; row++) {

           for (int col = 0; col < N; col++) {

               if (board[row][col] == 0) {

                   return new int[]{row, col};

               }

           }

       }

       return null;

   }

   

   public static boolean isValidMove(int[][] board, int row, int col, int num) {

       return isValidRow(board, row, num) &&

              isValidCol(board, col, num) &&

              isValidRegion(board, row - row % 3, col - col % 3, num);

   }

   

   public static boolean isValidRow(int[][] board, int row, int num) {

       for (int col = 0; col < board.length; col++) {

           if (board[row][col] == num) {

               return false;

           }

       }

       return true;

   }

   

   public static boolean isValidCol(int[][] board, int col, int num) {

       for (int row = 0; row < board.length; row++) {

           if (board[row][col] == num) {

               return false;

           }

       }

       return true;

   }

   

   public static boolean isValidRegion(int[][] board, int startRow, int startCol, int num) {

       for (int row = 0; row < 3; row++) {

           for (int col = 0; col < 3; col++) {

               if (board[row + startRow][col + startCol] == num) {

                   return false;

               }

           }

       }

       return true;

   }

   

   public static void printBoard(int[][] board) {

       int N = board.length;

       for (int row = 0; row < N; row++) {

           for (int col = 0; col < N; col++) {

               System.out.print(board[row][col] + " ");

           }

           System.out.println();

       }

   }

   

   public static void main(String[] args) {

       int[][] puzzle = {

           {0, 0, 3, 0, 0, 8, 0, 2, 0},

           {6, 0, 0, 3, 0, 0, 0, 0, 9},

           {0, 9, 0, 7, 0, 0, 1, 0, 4},

           {9, 0, 0, 2, 0, 0, 5, 4, 3},

           {0, 8, 0, 4, 0, 1, 0, 0, 0},

           {4, 6, 2, 0, 0, 7, 0, 0, 1},

           {1, 0, 6, 0, 0, 3, 0, 9, 0},

           {8, 0, 0, 0, 0, 9, 3, 0, 6},

           {0, 3, 0, 6, 0, 0, 7, 0, 0}

       };

       

       if (solveSudoku(puzzle)) {

           printBoard(puzzle);

       } else {

           System.out.println("No solution exists.");

       }

   }

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education