General
Computer Science
-
1. Introduction to Computer Science
-
Introduction to Computer Science
-
History of Computer Science
-
Fundamentals of Computer Science
-
Algorithms
-
Data Structures
-
Programming Concepts
-
Web Development
-
Databases and SQL
-
Networking and Security
-
Artificial Intelligence and Machine Learning
-
Mobile App Development
-
Game Development
-
Future of Computer Science
-
Careers in Computer Science
Legacy Course
Searching Algorithms
Searching algorithms are methods used to locate a specific piece of data within a larger collection of data. Two common searching algorithms are linear search and binary search.
Linear search, also known as sequential search, is a simple searching algorithm that starts at the first element of a collection and compares each element to the target item. If the element matches the target, the search is complete. If not, the search moves to the next element until the target is found or the end of the collection is reached.
The time complexity of linear search is O(n), where n is the number of elements in the collection. This means that, on average, the search will take n/2 comparisons to find the target item. The space complexity of linear search is O(1), as it only requires a single variable to storeThe stage where the CPU saves the result of the execution back into memory or registers. the current element being compared.
Binary search, on the other hand, is a more efficient searching algorithm that can only be used on sorted collections. The algorithm starts by finding the middle element of the collection and comparing it to the target item. If the middle element is the target, the search is complete. If the target is smaller than the middle element, the search continues on the left half of the collection. If the target is larger than the middle element, the search continues on the right half of the collection. This process is repeated until the target is found or the search reaches an empty collection.
The time complexity of binary search is O(log n), where n is the number of elements in the collection. This means that, on average, the search will take log(n) comparisons to find the target item. The space complexity of binary search is also O(1), as it only requires a single variable to store the current middle element.
Continue the lesson
This section is available to learners with course access. Continue learning with Knowness to unlock the full explanation, examples, revision tools, and progress tracking.
The remaining lesson content includes further guided explanation, important learning points, and supporting interactive material designed to help you understand and revise this topic.
Unlock this topic to view the full activity, worked examples, common mistakes, and additional revision support.
More content available
Knowness lessons are structured to build understanding step by step. Create an account or upgrade your access to continue from this point.
This preview does not include the hidden lesson text, answers, explanations, or embedded interactions.
Continue learning with Knowness
Sign up to access the full lesson, predicted grades, revision tools, progress tracking, and more.
Create a free account