Skip to content

Commit 7c690a5

Browse files
committed
Merge branch 'master' of https://github.com/Andruid929/algo-java into linkedstack
- Fell 2 commits behind while working
2 parents 650a622 + 14b6f99 commit 7c690a5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/main/java/com/thealgorithms/searches/JumpSearch.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
* <b>Space Complexity:</b> O(1) - only uses a constant amount of extra space
3737
*
3838
* <p>
39+
* <b>Edge Cases:</b>
40+
* <ul>
41+
* <li>Empty array → returns -1</li>
42+
* <li>Element not present → returns -1</li>
43+
* <li>Single element array</li>
44+
* </ul>
45+
* <p>
3946
* <b>Note:</b> Jump Search requires a sorted array. For unsorted arrays, use Linear Search.
4047
* Compared to Linear Search (O(n)), Jump Search is faster for large arrays.
4148
* Compared to Binary Search (O(log n)), Jump Search is less efficient but may be

src/test/java/com/thealgorithms/searches/IterativeBinarySearchTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ void testBinarySearchEmptyArray() {
8787
assertEquals(-1, binarySearch.find(array, key), "The element should not be found in an empty array.");
8888
}
8989

90+
/**
91+
* Test for binary search with a null array.
92+
*/
93+
@Test
94+
void testBinarySearchNullArray() {
95+
IterativeBinarySearch binarySearch = new IterativeBinarySearch();
96+
Integer key = 1;
97+
assertEquals(-1, binarySearch.find(null, key), "The element should not be found in a null array.");
98+
}
99+
100+
/**
101+
* Test for binary search with a null key.
102+
*/
103+
@Test
104+
void testBinarySearchNullKey() {
105+
IterativeBinarySearch binarySearch = new IterativeBinarySearch();
106+
Integer[] array = {1, 2, 4, 8, 16};
107+
assertEquals(-1, binarySearch.find(array, null), "A null search key should return -1.");
108+
}
109+
90110
/**
91111
* Test for binary search on a large array.
92112
*/

0 commit comments

Comments
 (0)