forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BAEL-19135] - Move search articles to a new module
- Loading branch information
1 parent
dd4aae6
commit 5e7d875
Showing
31 changed files
with
744 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...miscellaneous-4/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Algorithms - Searching | ||
|
||
This module contains articles about searching algorithms. | ||
|
||
### Relevant articles: | ||
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search) | ||
- [Depth First Search in Java](https://www.baeldung.com/java-depth-first-search) | ||
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search) | ||
- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search) | ||
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms) | ||
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>algorithms-searching</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>algorithms-searching</name> | ||
|
||
<parent> | ||
<groupId>com.baeldung</groupId> | ||
<artifactId>parent-modules</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${org.assertj.core.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>algorithms-searching</finalName> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<properties> | ||
<org.assertj.core.version>3.9.0</org.assertj.core.version> | ||
</properties> | ||
|
||
</project> |
110 changes: 55 additions & 55 deletions
110
...algorithms/binarysearch/BinarySearch.java → ...algorithms/binarysearch/BinarySearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package com.baeldung.algorithms.binarysearch; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class BinarySearch { | ||
|
||
public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { | ||
|
||
int index = Integer.MAX_VALUE; | ||
|
||
while (low <= high) { | ||
|
||
int mid = (low + high) / 2; | ||
|
||
if (sortedArray[mid] < key) { | ||
low = mid + 1; | ||
} else if (sortedArray[mid] > key) { | ||
high = mid - 1; | ||
} else if (sortedArray[mid] == key) { | ||
index = mid; | ||
break; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) { | ||
|
||
int middle = (low + high) / 2; | ||
if (high < low) { | ||
return -1; | ||
} | ||
|
||
if (key == sortedArray[middle]) { | ||
return middle; | ||
} else if (key < sortedArray[middle]) { | ||
return runBinarySearchRecursively(sortedArray, key, low, middle - 1); | ||
} else { | ||
return runBinarySearchRecursively(sortedArray, key, middle + 1, high); | ||
} | ||
} | ||
|
||
public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) { | ||
int index = Arrays.binarySearch(sortedArray, key); | ||
return index; | ||
} | ||
|
||
public int runBinarySearchUsingJavaCollections(List<Integer> sortedList, Integer key) { | ||
int index = Collections.binarySearch(sortedList, key); | ||
return index; | ||
} | ||
|
||
} | ||
package com.baeldung.algorithms.binarysearch; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class BinarySearch { | ||
|
||
public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { | ||
|
||
int index = Integer.MAX_VALUE; | ||
|
||
while (low <= high) { | ||
|
||
int mid = (low + high) / 2; | ||
|
||
if (sortedArray[mid] < key) { | ||
low = mid + 1; | ||
} else if (sortedArray[mid] > key) { | ||
high = mid - 1; | ||
} else if (sortedArray[mid] == key) { | ||
index = mid; | ||
break; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) { | ||
|
||
int middle = (low + high) / 2; | ||
if (high < low) { | ||
return -1; | ||
} | ||
|
||
if (key == sortedArray[middle]) { | ||
return middle; | ||
} else if (key < sortedArray[middle]) { | ||
return runBinarySearchRecursively(sortedArray, key, low, middle - 1); | ||
} else { | ||
return runBinarySearchRecursively(sortedArray, key, middle + 1, high); | ||
} | ||
} | ||
|
||
public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) { | ||
int index = Arrays.binarySearch(sortedArray, key); | ||
return index; | ||
} | ||
|
||
public int runBinarySearchUsingJavaCollections(List<Integer> sortedList, Integer key) { | ||
int index = Collections.binarySearch(sortedList, key); | ||
return index; | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.