Linear Search

Implement the linear search algorithm to find elements in an array by checking each element sequentially. This fundamental algorithm introduces you to algorithmic thinking and time complexity analysis with O(n) worst-case performance.

~0.5 hours
3 steps (+1 bonus)

Data Structures & Algorithms Project

The difficulty level shown is relative to other DSA projects. This project assumes you're comfortable with C++ fundamentals including classes, pointers, and memory management. If you're new to C++, we recommend completing our core C++ lessons first.

Support Free C++ Education

Help us keep this platform free for everyone! Your support enables us to create more high-quality lessons, exercises, and interactive content.

Become a Patron

What You'll Build

A complete linear search implementation with functions to find single elements, find all occurrences, and search with custom conditions using predicates.

Learning Objectives

  • Understand how linear search examines elements sequentially
  • Analyze O(n) time complexity for best, worst, and average cases
  • Implement linear_search() returning index or -1 for not found
  • Create find_all() to locate all occurrences of a value
  • Use predicates for flexible conditional searching
  • Recognize when linear search is the appropriate choice

Ready to Start?

Start Project

Sign in to retain your progress

Project Steps

Step 1

Understanding Linear Search

Learn how linear search works by examining each element sequentially and understand when to use this fundamental algorithm.

~10 min
Step 2

Template-Based Linear Search

Convert the linear search function to a template that works with any data type using std::array, enabling reusable search functionality.

~10 min
Step 3

Finding All Occurrences and Conditional Search

Extend linear search with find_all() to locate multiple occurrences, find_if() for predicate-based searching, and count() to count matches.

~10 min
Step 4

Interview Prep

Practice common interview questions about linear search, time complexity, and algorithm selection.

~15 min

Ready to Start?

Start Project

Sign in to retain your progress