Save
...
2.1 Algorithms
2.1.3 Searching and Sorting Algorithms
Understanding the following standard searching algorithms
Save
Share
Learn
Content
Leaderboard
Share
Learn
Cards (30)
Linear Search
sequentially checks each element in the data structure until the target is found or the
end
is reached.
Match the time complexity with the searching algorithm:
Linear Search ↔️ O(n)
Binary Search ↔️ O(log n)
Linear search is suitable for
unsorted
data.
What is the worst-case time complexity of linear search?
O(n)
Binary Search
is a searching algorithm that efficiently locates a specific item within a
sorted
data structure.
What is the time complexity of binary search?
O(log n)
What type of datasets is binary search most suitable for?
Large, sorted datasets
What is the primary goal of the Linear Search algorithm?
Find a target value
If the target value is not found in Linear Search, the algorithm returns -1.
True
The worst-case time complexity of Linear Search is
O(n)
The time complexity of Binary Search is
O(log n)
Binary Search has a higher time complexity than Linear Search for unsorted data.
False
When is Binary Search most suitable for use?
Large, sorted datasets
Binary Search has a time complexity of O(n).
False
What is a searching algorithm used for?
Finding items in data
Linear search is suitable for sorted data.
False
What is the primary characteristic of linear search?
Checks sequentially
Steps in the linear search algorithm:
1️⃣ Start from the first element
2️⃣ Compare each element to the target value
3️⃣ If a match is found, return the index
4️⃣ If the entire structure is traversed, return -1
Linear search is more complex to implement than binary search.
False
Steps in the binary search algorithm:
1️⃣ Start with the middle element
2️⃣ Compare the middle element with the target value
3️⃣ If the target is less, search the left half
4️⃣ If the target is greater, search the right half
Binary search requires data to be sorted beforehand.
True
The time complexity of binary search is
O(log n)
.
What does linear search check in each step?
Each element sequentially
The Linear Search algorithm starts from the first
element
For what type of data is Linear Search suitable?
Unsorted data
What is the data requirement for Binary Search?
Sorted data
Binary Search repeatedly divides the search interval in half to locate the
target
value.
True
In Binary Search, what happens if the target is less than the middle element?
Search left half
Steps of the Binary Search algorithm:
1️⃣ Start with the entire sorted array
2️⃣ Find the middle element
3️⃣ Compare the target with the middle element
4️⃣ Narrow the search interval
5️⃣ Repeat until the target is found or the interval is empty
Linear Search requires
unsorted
data.