Linear Search -This is a one of the method used for search a array
we can search entire array and it will work on the sorted array and unsorted array .it's the usefull one in dsa for me also.
public class LinearSearchExample {
public static int linearSearch(int[] arr, int target) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == target) {
return i; // Return the index where target is found
}
}
return -1; // Target not found
}
}
Top comments (0)