SE 504 Spring 2022
Prog. Assg.: Saddleback Search
Due: 11:59pm, Friday, May 13

SaddleBack Search Programming Assignment

For a discussion of how to employ the binary search approach when searching a two-dimensional array (whose elements are increasing along each row and column), go here.

Provided to you are the following Java components:

For testing purposes, the following Java classes are provided:


Dialog with SB_Tester

$ java SB_Tester
Welcome to the SaddleBackSearcher tester.
Enter # rows in matrix: 10
Enter # columns in matrix: 11
Enter seed for pseudorandom # generation: 5

        0   1   2   3   4   5   6   7   8   9  10
    +--------------------------------------------
   0|   5   8  13  18  20  21  26  28  31  33  35
   1|   9  13  14  22  24  26  29  30  34  35  36
   2|  12  18  21  25  30  33  34  36  40  45  49
   3|  13  23  25  26  33  35  39  42  45  49  50
   4|  17  24  26  29  36  40  43  48  49  52  54
   5|  18  29  31  34  38  44  45  52  55  60  64
   6|  22  34  36  40  41  45  48  57  58  64  69
   7|  23  35  40  45  49  51  53  61  63  66  72
   8|  26  39  42  46  51  52  54  64  69  74  75
   9|  29  40  46  47  55  60  65  69  70  79  84

Enter a search key (or Q, or S): 30

Searching by Elimination...
The search for 30 involved 18 probes and yielded this list of locations:
[(1,7), (2,4)]

Searching by Binary Search...
The search for 30 involved 29 probes and yielded this list of locations:
[(1,7), (2,4)]

Enter a search key (or Q, or S): 22

Searching by Elimination...
The search for 22 involved 16 probes and yielded this list of locations:
[(1,3), (6,0)]

Searching by Binary Search...
The search for 22 involved 24 probes and yielded this list of locations:
[(6,0), (1,3)]

Enter a search key (or Q, or S): 59

Searching by Elimination...
The search for 59 involved 16 probes and yielded this list of locations:
[]

Searching by Binary Search...
The search for 59 involved 22 probes and yielded this list of locations:
[]

Enter a search key (or Q, or S): S

        0   1   2   3   4   5   6   7   8   9  10
    +--------------------------------------------
   0|   5   8  13  18  20  21  26  28  31  33  35
   1|   9  13  14  22  24  26  29  30  34  35  36
   2|  12  18  21  25  30  33  34  36  40  45  49
   3|  13  23  25  26  33  35  39  42  45  49  50
   4|  17  24  26  29  36  40  43  48  49  52  54
   5|  18  29  31  34  38  44  45  52  55  60  64
   6|  22  34  36  40  41  45  48  57  58  64  69
   7|  23  35  40  45  49  51  53  61  63  66  72
   8|  26  39  42  46  51  52  54  64  69  74  75
   9|  29  40  46  47  55  60  65  69  70  79  84

Enter a search key (or Q, or S): 18

Searching by Elimination...
The search for 18 involved 14 probes and yielded this list of locations:
[(0,3), (2,1), (5,0)]

Searching by Binary Search...
The search for 18 involved 21 probes and yielded this list of locations:
[(5,0), (2,1), (0,3)]

Enter a search key (or Q, or S): Q
Goodbye from the SaddleBackSearcher tester.