CJCoding With Joseph
15free / daySign inCreate account

University of Lethbridge - CPSC

Searching for a Movie with Linear Search

Assignment 1 - Movie1 - SM 25

What does this function do?

This function checks every movie title one by one to see if it matches the search term the user typed.

If it finds the title:

  • It saves the matching movie’s year in year_result

  • It returns true

If it doesn’t find the title:

  • It returns false

It also keeps track of how many comparisons it made using the comparisons variable. This lets us compare how efficient linear search is compared to binary search.


Why are we using linear search?

Linear search is the most basic search method. It doesn’t require the list to be sorted, and it’s easy to understand:

Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 27 more lessons in University of Lethbridge - CPSC.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.