From 17c118cb1c16708d48a3aff05f0d823325ba52cd Mon Sep 17 00:00:00 2001
From: Yawar Ali
Date: Tue, 28 Apr 2026 19:56:33 +0500
Subject: [PATCH] docs: improve LinearSearch JavaDocs and complexity analysis
---
.../thealgorithms/searches/LinearSearch.java | 44 +++++++------------
1 file changed, 17 insertions(+), 27 deletions(-)
diff --git a/src/main/java/com/thealgorithms/searches/LinearSearch.java b/src/main/java/com/thealgorithms/searches/LinearSearch.java
index 3f273e167f0a..61c037a2a742 100644
--- a/src/main/java/com/thealgorithms/searches/LinearSearch.java
+++ b/src/main/java/com/thealgorithms/searches/LinearSearch.java
@@ -1,47 +1,37 @@
-/**
- * Performs Linear Search on an array.
- *
- * Linear search checks each element one by one until the target is found
- * or the array ends.
- *
- * Example:
- * Input: [2, 4, 6, 8], target = 6
- * Output: Index = 2
- *
- * Time Complexity: O(n)
- * Space Complexity: O(1)
- */
package com.thealgorithms.searches;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
/**
- * Linear Search is a simple searching algorithm that checks
- * each element of the array sequentially until the target
- * value is found or the array ends.
+ * Linear Search is a simple searching algorithm that checks each element
+ * of the array sequentially until the target value is found or the array ends.
*
- * It works for both sorted and unsorted arrays.
+ * It works for both sorted and unsorted arrays.
*
- * Time Complexity:
- * - Best case: O(1)
- * - Average case: O(n)
- * - Worst case: O(n)
+ * Time Complexity:
+ *
+ * - Best case: O(1) - Target is at the first index.
+ * - Average case: O(n) - Target is in the middle.
+ * - Worst case: O(n) - Target is at the end or missing.
+ *
+ *
*
- * Space Complexity: O(1)
+ * Space Complexity: O(1)
*
* @author Varun Upadhyay
* @author Podshivalov Nikita
+ * @author yawarali1
* @see BinarySearch
* @see SearchAlgorithm
*/
public class LinearSearch implements SearchAlgorithm {
/**
- * Generic Linear search method
+ * Generic Linear search method.
*
- * @param array List to be searched
- * @param value Key being searched for
- * @return Location of the key, -1 if array is null or empty, or key not found
+ * @param array List to be searched.
+ * @param value Key being searched for.
+ * @return Location of the key, -1 if array is null or empty, or key not found.
*/
@Override
public > int find(T[] array, T value) {
@@ -59,4 +49,4 @@ public > int find(T[] array, T value) {
return -1;
}
-}
+}
\ No newline at end of file