To understand searching better, consider the following example.
Let's say that you've 500 students in your school. One day, your principal asks you to locate one student, but you've only been given some details about them. You can do this task in multiple ways. Let's explore a couple of possible approaches:
- Approach 1: You can go and visit each of the students and check if they are the student your principal has asked for. This will take quite a long time, as your search might end with the very last student.
- Approach 2: Instead of visiting each student randomly, you can check which class the student belongs to, and only visit the students from that class. This will significantly reduce your search time.
From the preceding two approaches, it's obvious that you'll always choose the second one because it significantly...