Skip to content

Commit 17c118c

Browse files
committed
docs: improve LinearSearch JavaDocs and complexity analysis
1 parent 35b94ab commit 17c118c

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
1-
/**
2-
* Performs Linear Search on an array.
3-
*
4-
* Linear search checks each element one by one until the target is found
5-
* or the array ends.
6-
*
7-
* Example:
8-
* Input: [2, 4, 6, 8], target = 6
9-
* Output: Index = 2
10-
*
11-
* Time Complexity: O(n)
12-
* Space Complexity: O(1)
13-
*/
141
package com.thealgorithms.searches;
152

163
import com.thealgorithms.devutils.searches.SearchAlgorithm;
174

185
/**
19-
* Linear Search is a simple searching algorithm that checks
20-
* each element of the array sequentially until the target
21-
* value is found or the array ends.
6+
* Linear Search is a simple searching algorithm that checks each element
7+
* of the array sequentially until the target value is found or the array ends.
228
*
23-
* It works for both sorted and unsorted arrays.
9+
* <p>It works for both sorted and unsorted arrays.</p>
2410
*
25-
* Time Complexity:
26-
* - Best case: O(1)
27-
* - Average case: O(n)
28-
* - Worst case: O(n)
11+
* <p>Time Complexity:
12+
* <ul>
13+
* <li>Best case: O(1) - Target is at the first index.</li>
14+
* <li>Average case: O(n) - Target is in the middle.</li>
15+
* <li>Worst case: O(n) - Target is at the end or missing.</li>
16+
* </ul>
17+
* </p>
2918
*
30-
* Space Complexity: O(1)
19+
* <p>Space Complexity: O(1)</p>
3120
*
3221
* @author Varun Upadhyay
3322
* @author Podshivalov Nikita
23+
* @author yawarali1
3424
* @see BinarySearch
3525
* @see SearchAlgorithm
3626
*/
3727
public class LinearSearch implements SearchAlgorithm {
3828

3929
/**
40-
* Generic Linear search method
30+
* Generic Linear search method.
4131
*
42-
* @param array List to be searched
43-
* @param value Key being searched for
44-
* @return Location of the key, -1 if array is null or empty, or key not found
32+
* @param array List to be searched.
33+
* @param value Key being searched for.
34+
* @return Location of the key, -1 if array is null or empty, or key not found.
4535
*/
4636
@Override
4737
public <T extends Comparable<T>> int find(T[] array, T value) {
@@ -59,4 +49,4 @@ public <T extends Comparable<T>> int find(T[] array, T value) {
5949

6050
return -1;
6151
}
62-
}
52+
}

0 commit comments

Comments
 (0)