+1 vote
in Mean Stack by
State the difference between linear search and binary search.

1 Answer

0 votes
by

A linear search considers a list’s item’s one by one without jumping sequence. So, in terms of complexity, it classifies as an O(n) search wherein the time taken to search the list increases proportionally to the increase in the list. Contrary to this, a binary search starts in the middle of a list. This search aims to see whether the item value is greater than or less than the desired value.

This further determines the position of the value in the list – whether it will be in the first part or second part of the list. In terms of complexity, it classifies as an O(log n) search where the number of search operations grows relatively slowly than the list. This is mainly because the search space is broken into half in each operation.

While binary search requires you to sort the input data first, a linear list doesn’t have any such prerequisites.

Related questions

+2 votes
asked Jun 21, 2021 in Mean Stack by SakshiSharma
0 votes
0 votes
asked Dec 8, 2022 in Data Structures & Algorithms by sharadyadav1986
...