Skip to content

Commit 5e7d875

Browse files
[BAEL-19135] - Move search articles to a new module
1 parent dd4aae6 commit 5e7d875

File tree

31 files changed

+744
-327
lines changed

31 files changed

+744
-327
lines changed

algorithms-miscellaneous-1/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
77

88
- [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata)
99
- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm)
10-
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
11-
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search)
1210
- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
1311
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
1412
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)

algorithms-miscellaneous-3/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
1414
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
1515
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
1616
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
17-
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search)
1817
- [The K-Means Clustering Algorithm in Java](https://www.baeldung.com/java-k-means-clustering-algorithm)
1918
- [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation)
20-
- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search)
2119
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)

algorithms-miscellaneous-4/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
55
### Relevant articles:
66

77
- [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm)
8-
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
98
- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
109
- [Find the Middle Element of a Linked List](https://www.baeldung.com/java-linked-list-middle-element)
1110
- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)

algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

algorithms-searching/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Algorithms - Searching
2+
3+
This module contains articles about searching algorithms.
4+
5+
### Relevant articles:
6+
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search)
7+
- [Depth First Search in Java](https://www.baeldung.com/java-depth-first-search)
8+
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search)
9+
- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search)
10+
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
11+
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)

algorithms-searching/pom.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>algorithms-searching</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<name>algorithms-searching</name>
7+
8+
<parent>
9+
<groupId>com.baeldung</groupId>
10+
<artifactId>parent-modules</artifactId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
</parent>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.assertj</groupId>
17+
<artifactId>assertj-core</artifactId>
18+
<version>${org.assertj.core.version}</version>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
22+
23+
<build>
24+
<finalName>algorithms-searching</finalName>
25+
<resources>
26+
<resource>
27+
<directory>src/main/resources</directory>
28+
<filtering>true</filtering>
29+
</resource>
30+
</resources>
31+
</build>
32+
33+
<properties>
34+
<org.assertj.core.version>3.9.0</org.assertj.core.version>
35+
</properties>
36+
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
package com.baeldung.algorithms.binarysearch;
2-
3-
import java.util.Arrays;
4-
import java.util.Collections;
5-
import java.util.List;
6-
7-
public class BinarySearch {
8-
9-
public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
10-
11-
int index = Integer.MAX_VALUE;
12-
13-
while (low <= high) {
14-
15-
int mid = (low + high) / 2;
16-
17-
if (sortedArray[mid] < key) {
18-
low = mid + 1;
19-
} else if (sortedArray[mid] > key) {
20-
high = mid - 1;
21-
} else if (sortedArray[mid] == key) {
22-
index = mid;
23-
break;
24-
}
25-
}
26-
return index;
27-
}
28-
29-
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
30-
31-
int middle = (low + high) / 2;
32-
if (high < low) {
33-
return -1;
34-
}
35-
36-
if (key == sortedArray[middle]) {
37-
return middle;
38-
} else if (key < sortedArray[middle]) {
39-
return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
40-
} else {
41-
return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
42-
}
43-
}
44-
45-
public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) {
46-
int index = Arrays.binarySearch(sortedArray, key);
47-
return index;
48-
}
49-
50-
public int runBinarySearchUsingJavaCollections(List<Integer> sortedList, Integer key) {
51-
int index = Collections.binarySearch(sortedList, key);
52-
return index;
53-
}
54-
55-
}
1+
package com.baeldung.algorithms.binarysearch;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
public class BinarySearch {
8+
9+
public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
10+
11+
int index = Integer.MAX_VALUE;
12+
13+
while (low <= high) {
14+
15+
int mid = (low + high) / 2;
16+
17+
if (sortedArray[mid] < key) {
18+
low = mid + 1;
19+
} else if (sortedArray[mid] > key) {
20+
high = mid - 1;
21+
} else if (sortedArray[mid] == key) {
22+
index = mid;
23+
break;
24+
}
25+
}
26+
return index;
27+
}
28+
29+
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
30+
31+
int middle = (low + high) / 2;
32+
if (high < low) {
33+
return -1;
34+
}
35+
36+
if (key == sortedArray[middle]) {
37+
return middle;
38+
} else if (key < sortedArray[middle]) {
39+
return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
40+
} else {
41+
return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
42+
}
43+
}
44+
45+
public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) {
46+
int index = Arrays.binarySearch(sortedArray, key);
47+
return index;
48+
}
49+
50+
public int runBinarySearchUsingJavaCollections(List<Integer> sortedList, Integer key) {
51+
int index = Collections.binarySearch(sortedList, key);
52+
return index;
53+
}
54+
55+
}

0 commit comments

Comments
 (0)