CJCoding With Joseph
15free / daySign inCreate account

University of Lethbridge - CPSC

Searching for a Movie with Binary Search

Assignment 1 - Movie1 - SM 25

What does this function do?

This function searches through the list of movie titles using binary search. Instead of checking one by one like linear search, it cuts the list in half each time until it either finds the title or confirms it isn’t there.

If a match is found:

  • The function returns true

  • It saves the movie’s release year into year_result

If no match is found:

  • The function returns false

The function also updates the comparisons variable to show how many times it had to check a title before finding or not finding a match.


Explaining the Parameters

bool binary_search(const string titles[], const int years[], int n, string target, int &comparisons, int &year_result)
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.