• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

🔎 Introduction to Linear Search (Beginner-Friendly DSA)

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,483
Баллы
155


Hey friends!

I'm late today again😂. I'm almost done with the two full-stack apps I'm building, so I'll be on time next week.

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.

🤔 What is 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



⏱ Time Complexity

  • 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)

👉

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



🙋🏽‍♀️ Over to You!


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

But before then —
👉 Can you try writing your own version of Linear Search using a while loop instead of a for loop?

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 💬 or 🧡 to let me know.

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

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



✍🏾 I’m documenting my learning loudly every Wednesday. Follow along if you're learning JavaScript too!
Let’s keep learning together!



Источник:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу