Buy/Download all MCQ Ebook >>>Click Here<<<
Data Structure Questions and Answers-Linear Search Iterative
Click on any option to know the CORRECT ANSWERS
Question 1 |
Where is linear searching used?
When the list has only a few elements | |
When performing a single search in an unordered list | |
Used all the time | |
When the list has only a few elements and When performing a single search in an unordered list |
Question 1 Explanation:
It is practical to implement linear search in the situations mentioned in When the list has only a few elements and When performing a single search in an unordered list, but for larger elements the complexity becomes larger and it makes sense to sort the list and employ binary search or hashing.
Question 2 |
Select the code snippet which performs unordered linear search iteratively?
int unorderedLinearSearch(int arr[], int size, int data) { int index; for(int i = 0; i < size; i++) { if(arr | ||||||||||||||||||||||||||||
int unorderedLinearSearch(int arr[], int size, int data) { int index; for(int i = 0; i <= size; i++) { if(arr
What is the best case for linear search?
Question 3 Explanation: The element is at the head of the array, hence O(1).
What is the worst case for linear search?
Question 4 Explanation: Worst case is when the desired element is at the tail of the array or not present at all, in this case you have to traverse till the end of the array, hence the complexity is O(n).
Select the code snippet which performs ordered linear search iteratively?
Question 5 Explanation: The term ordered refers to the items in the array being sorted(here we assume ascending order). So traverse through the array until the element, if at any time the value at i exceeds key value, it means the element is not present in the array. This provides a slightly better efficiency than unordered linear search.
There are 5 questions to complete.
Buy/Download all MCQ Ebook >>>CLICK HERE<<< |