edited by
524 views
0 votes
0 votes

Worst case scenario in case of linear search algorithm is ______________ .

  1. Item is somewhere in the middle of the array.
  2. Item is not in the array at all.
  3. Item is the last element in the array.
  4. Item is the last element in the array or is not there at all.
edited by

3 Answers

1 votes
1 votes

Answer is D

If an item is in the last place or not present in array then Linear search  algorithm have to check each element from the beginning and in the worst case it might be found as last element or possibility of not found.

 

1 votes
1 votes

Correct Answer Option B

Option A = False :- We Will Stop Midway Hence not covering the Whole Array 

Option B = True :- We Will Have to Traverse till the end of the array .

Option C = False :- We don’t need to Traverse till the end  We can just Check by using a simple conditional statement .

Option D = False :- ( Can Be True But Here is why i think its False ) → Option D still covers the Option C and we know Option C isnt the worst Case scenario . 

edited by
0 votes
0 votes

Lets assume an array A = [2,5,1,4,7]

Lets understand all the options,

  1. If we want to search for 1 using linear search, then we must go linearly so Time Complexity would be O(n/2) = O(n)
  2. If we want to search for 8 using linear search, then it would go until the last of the array and print a “not found” message so Time Complexity would be O(n)
  3. If we want to search for 7 using linear search, then it would directly go until the end so Time Complexity would be O(n)
  4. If we want to search for either 7 or 8 then whatsoever it is, it would go until the end and traverse the entire array ONLY ONCE but completely traverse so Time Complexity would be O(n) again.

So, as per my idea, All options would be correct (if it is an MSQ)

Now, if we choose to traverse the array in reverse,

  1. It would be the same O(n)
  2. It would also be the same O(n)
  3. Here, it would just need one check as we would see if the last element is our required element or not so O(1)
  4. It would again be O(n) 

Related questions

1 votes
1 votes
1 answer
1
soujanyareddy13 asked Jan 9, 2022
947 views
Let the predicates $D(x,y)$ mean “team $x$ defeated team $y$” and $P(x,y)$ mean “team $x$ has played team $y$”. The quantified formula for the statement that ther...
0 votes
0 votes
1 answer
2
soujanyareddy13 asked Jan 9, 2022
604 views
The File Transfer Protocol is built on ______________.data centric architectureservice-oriented architectureclient server architectureconnection-oriented architecture
0 votes
0 votes
1 answer
3
soujanyareddy13 asked Jan 9, 2022
529 views
More than one word is put in one cache block to:exploit the temporal locality of reference in a programexploit the spatial locality of reference in a programreduce the mi...
0 votes
0 votes
1 answer
4
soujanyareddy13 asked Jan 9, 2022
446 views
In $\text{DPSK}$ technique, the technique used to encode bits is :$\text{AMI}$Differential codeUnipolar $\text{RZ}$ formatManchester formate