difference between linear search and binary search

Answer:The main difference b/n Linear search and Binary search are given below:
Linear search: Linear search starts to search first records of the list and going on until it finds the matched record or to the end of list.In Linear Linked list their is no need to sort the file in a particular order.

Binary search: Their is three steps you have to follow when you using Binary search.

1.It starts with to select the middle item of the list.When the key item is less than the selected item than Binary search take the item between the current item and the start element of the list.Otherwise, if key item is greater than the selected item than Binary search take the item between the current item and the last element of the list.Benefit of its is that after taking one comparison it delete the half list.
2.If key item is less than the current item than we only take half list who is less than the key.Otherwise,If key item is greater than the current item than we only take half list who is greater than the key.And start in again.
3.We repeat step2 till we not reached our desired key.

No comments:

 
Top Blogs