Question: Implemement this program in Java. The instructions, skeleton program, and sample run are given below. --------------- Search2D.java package Lab10; public class Search2D { /** *

Implemement this program in Java. The instructions, skeleton program, and sample run are given below.

Implemement this program in Java. The instructions, skeleton program, and sample run

---------------

Search2D.java

package Lab10; public class Search2D { /**  * Searches for the desiredItem in a rectangular matrix[][] where  * elements are sorted within each row and within each column  * If the element is found, prints its position,  * otherwise prints "not found"  *  * @author YOUR NAME  * @version 10/30/2018  *  */   private void search(int[][] matrix, int desiredItem) { // TODO Project 5  System.out.println("Searching for " + desiredItem); } // driver to test search method public static void main(String[] args) { int matrix[][] = { {10, 20, 21, 40}, {15, 25, 26, 45}, {27, 29, 30, 48}, {32, 33, 34, 50}}; Search2D search2D = new Search2D(); System.out.println("*** These should be successful searches ***"); for (int r = 0; r out.println(" *** These should be successful searches ***"); search2D.search(matrix,28); search2D.search(matrix,5); search2D.search(matrix,100); } } 

------------------------

SAMPLE RUN:

*** These should be successful searches ***

Searching for 10

checking 40

checking 21

checking 20

checking 10

10 found at [0, 0]

Searching for 20

checking 40

checking 21

checking 20

20 found at [0, 1]

Searching for 21

checking 40

checking 21

21 found at [0, 2]

Searching for 40

checking 40

40 found at [0, 3]

Searching for 15

checking 40

checking 21

checking 20

checking 10

checking 15

15 found at [1, 0]

Searching for 25

checking 40

checking 21

checking 26

checking 25

25 found at [1, 1]

Searching for 26

checking 40

checking 21

checking 26

26 found at [1, 2]

Searching for 45

checking 40

checking 45

45 found at [1, 3]

Searching for 27

checking 40

checking 21

checking 26

checking 30

checking 29

checking 27

27 found at [2, 0]

Searching for 29

checking 40

checking 21

checking 26

checking 30

checking 29

29 found at [2, 1]

Searching for 30

checking 40

checking 21

checking 26

checking 30

30 found at [2, 2]

Searching for 48

checking 40

checking 45

checking 48

48 found at [2, 3]

Searching for 32

checking 40

checking 21

checking 26

checking 30

checking 34

checking 33

checking 32

32 found at [3, 0]

Searching for 33

checking 40

checking 21

checking 26

checking 30

checking 34

checking 33

33 found at [3, 1]

Searching for 34

checking 40

checking 21

checking 26

checking 30

checking 34

34 found at [3, 2]

Searching for 50

checking 40

checking 45

checking 48

checking 50

50 found at [3, 3]

*** These should be unsuccessful searches ***

Searching for 28

checking 40

checking 21

checking 26

checking 30

checking 29

checking 27

checking 32

28 not found

Searching for 5

checking 40

checking 21

checking 20

checking 10

5 not found

Searching for 100

checking 40

checking 45

checking 48

checking 50

100 not found found

Open Search2D class and implement efficient, non-recursive search methodthat searches for a desired item in a rectangulartwo-dimensional array of integers where elements are sorted within each row and within each column (see the following two-dimensional array) V. int matrixI0 10, 20, 21, 40), [15, 25, 26, 45), 127, 29, 30, 483, 132, 33, 34, 50 If the element is found, the method prints its position, otherwise it prints"not found". The algorithm must take into consideration the nature of the sorted data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!