Linear Search
A linear search simply iterates through every element in a linear data structure. For instance:
//Example data
int[] numbers = {4, 2, 1, 8, 7, 9, 4, 2, 4};
int targetNumber = 2;
Console.WriteLine($"My target number is: {targetNumber}");
//Linear search
for (int i = 0, i < numbers.Length, i++)
{
if(numbers[i] == targetNumber)
{
Console.WriteLine($"Target number found at index: {numbers[i]}");
}
}
My target number is: 2
Target number found at index: 1
Target number found at index: 7
A linear search checks each element in a dataset sequentially until it finds the desired element. Its main disadvantage is its slow speed for large datasets due to its