The correct time and space complexities of a linear search are:
- Time Complexity: O(n)
- Space Complexity: O(1)
Explanation:
-
Time Complexity (O(n)):
- In a linear search, you iterate through all the elements of a list to find a target value. In the worst case, you may have to check every element, which results in a time complexity of O(n), where n is the number of elements in the list.
-
Space Complexity (O(1)):
- The space complexity is considered O(1) because a linear search does not require any additional space that grows with the input size. It uses a constant amount of memory regardless of the input size (just a few variables for indexing and storing the target).
Therefore, the first option you provided is correct:
- time complexity: O(n)
- space complexity: O(1)
(Note: O(1) was not listed in your response options, but it's the correct space complexity for a linear search.)