- Регистрация
- 9 Май 2015
- Сообщения
- 1,483
- Баллы
- 155

Hey friends!
I'm late today again

Check them out on my if you're curious :)
It’s another tutorial Wednesday, and today we’re stepping into the world of Data Structures & Algorithms (DSA). Don’t worry, it sounds fancy but we’ll keep it simple and fun

We’ll start with one of the most basic (but powerful) search algorithms: Linear Search.

Linear search is like checking through a shopping list one item at a time:
- You look at the first item → if it’s not what you want, move to the next.
- Repeat until you find it (or reach the end).
Simple! No shortcuts. Just checking one by one.
How Linear Search Works in Code
function linearSearch(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr === target) {
return i; // found at index i
}
}
return -1; // not found
}
// Example:
const items = [10, 20, 30, 40];
console.log(linearSearch(items, 30)); // 2
console.log(linearSearch(items, 50)); // -1

- Best case: O(1) → target is at the start.
- Worst case: O(n) → target is at the end or not present.
Think of it like searching your name on an attendance list. If you’re the first name, lucky! Otherwise, you might have to go through the whole list.
Try It Yourself (Interactive Demo)
I built a small playground where you can:
- Enter an array
- Enter a number to search
- See if it’s found (and where)


Linear Search is simple but forms the foundation of searching algorithms. Next time, we can explore faster ones (like Binary Search).
But before then —

Let me know if you do the challenge! I'd like to see yours! Connect with me on
Was this tutorial helpful? Got questions? Or any insight to help me write better tutorials? Let me know in the

That’s it for today’s midweek mini tutorial!
I’m keeping things light, fun and useful; one small project at a time.
If you enjoyed this, leave a


And if you’ve got an idea for something you'd like me to try out next Wednesday, drop it in the comments.

Follow me to see more straight-forward and short tutorials like this :)
If you are curious about what I do, check out my
:-)
Web trails
You can also find me here on
or here

Let’s keep learning together!
See you next Wednesday![]()
Источник: