Question:
Which one is faster? A binary search of an orderd set of elements in an array or a sequential search of the elements.
Answer:
Binary search is faster because we traverse the elements by using the policy of Divide and Conquer. we compare the key element with the approximately center element, if it is smaller than it search is applied in the smaller elements only otherwise the search is applied in the larger set of elements. its complexity is as we all know is log n as compared to the sequential one whose complexity is n. Source: CoolInterview.com
Binary search follows Divide and Conquer method where as linear Search doesn't follw.The time complexity of Binary Search in O(log n) but incase of linear search the time complexity is O(n). Thats way Binary search is having bettr prior than linear search. But it is true when the list of items is large incase of smaller list linear is best(i.e.- it is only when the Best Case concern) Source: CoolInterview.com
Answered by: kumaraswamy dapa | Date: 3/1/2010
| Contact kumaraswamy dapa
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|