Linear Search Algorithm
📖 Scenario: You have a list of product IDs in a store inventory. You want to find if a specific product ID is available in the list.
🎯 Goal: Build a simple program that uses linear search to find the position of a product ID in the list.
📋 What You'll Learn
Create a slice of integers called
products with the exact values: 101, 203, 405, 302, 101, 509Create an integer variable called
target with the value 302Write a
for loop using the index variable i to iterate over productsInside the loop, use an
if statement to check if products[i] equals targetIf found, print the message
"Product found at index: " followed by the index iIf not found after the loop, print
"Product not found"💡 Why This Matters
🌍 Real World
Searching for items in a list is common in inventory management, contact lists, or any collection of data.
💼 Career
Understanding linear search helps in debugging and optimizing simple search tasks before moving to advanced algorithms.
Progress0 / 4 steps