Searching means finding a specific value (the target) inside a list or array. You have many items and you want to know where one of them is, or if it is there at all.
Like finding a contact in your phone: you scroll until you see the name. Or like finding a word in a dictionary: you open the middle and then go left or right. Both are searching; the strategy is different.
Searching is finding a specific Target in a crowd.
We do this every day: finding a contact, finding a sock in a drawer, or searching on the web.
Let's build this from the ground up.
What is searching?
You have a list of items (numbers, names, or anything). You want to find one item in that list. That item is called the target. Searching is the process of checking the list until you find the target or until you know it is not there.
Everyday examples
We do this every day: finding a contact in your phone, finding a sock in a drawer, or typing a query in Google. In code, we might have an array of numbers and need to find where 42 is, or we might have a list of names and need to check if "Alice" is in it.
Two main strategies
In this module we look at two ways to search: linear search (check one by one from the start) and binary search (only for sorted lists; cut the list in half each time). The first works on any list. The second is much faster but needs the list to be sorted.
Programs search all the time: find a contact by name, find a product in a list, or check if a user exists. The way you search (linear or binary) decides how fast your program runs when the list gets big.
"What is searching, and what do we call the value we are looking for?"
Searching is finding a specific value inside a list or array. The value we look for is called the target.