Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Lab03P3Wrapper { public static boolean isValidSudoku(char[][] board) { /*ADD YOUR CODE HERE*/ int n = 10; int[][] row=new int[n][n]; int[][] col =new int[n][n];

public class Lab03P3Wrapper { public static boolean isValidSudoku(char[][] board) { /*ADD YOUR CODE HERE*/ int n = 10; int[][] row=new int[n][n]; int[][] col =new int[n][n]; int[][][] square=new int[3][3][n]; for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { if(board[i][j]=='.')continue; int num = (board[i][j]-'0'); row[i][num]++; col[j][num]++; square[i/3][j/3][num]++; if(row[i][num]>1){ return false; } if(col[i][j]>1) { return false; } if(square[i/3][j/3][num]>1) { return false; } } } return true; } public static void main(String[] args) { char[][] board ={{'5','3','.','.','7','.','.','.','.'} ,{'6','.','.','1','9','5','.','.','.'} ,{'.','9','8','.','.','.','.','6','.'} ,{'8','.','.','.','6','.','.','.','3'} ,{'4','.','.','8','.','3','.','.','1'} ,{'7','.','.','.','2','.','.','.','6'} ,{'.','6','.','.','.','.','2','8','.'} ,{'.','.','.','4','1','9','.','.','5'} ,{'.','.','.','.','8','.','.','7','9'}}; System.out.println(isValidSudoku(board)); // Dummy Return } }

For the problem solved above, answer the following items:

What is the running time of the algorithm implemented? Explain your thought process behind the implementation

Describe in detail the running time breaking down each part of the code implemented into its respective runtimes

Does this code have a more optimal solution than the one implemented? If so, explain why, how and what would you change from your code to optimize said solution

If your code does not meet the minimum runtime requirements, add below a pseudocode of your implementation for the optimal solution. It does not have to follow any specific syntax, it's pseudocode. (If it does meet the minimum requirements, ignore this question)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

Distinguish between hearing and listening.

Answered: 1 week ago

Question

Use your voice effectively.

Answered: 1 week ago