what is the difference b/w linear search and binary search?
(how can these search)
Answers were Sorted based on User's Feedback
Answer / vandan
in case of linear search system will search from begining.
that means Example : z table contains single field with values
1 2 3 4 5 6 7 8 9
if u r searching for a value then system will starts from
first position. if required value is founded then execution
will comes out from z table.
in case of binary search system will starts from mid point.
if value is not founded then it will search for upper half.
in that upper half it will check mid point.like that search
will takes place.
Is This Answer Correct ? | 112 Yes | 26 No |
Answer / jayati saha
Linear search is ver easy and always search in sequential
way.
It starts searching from the first element upto the last
element until the search finds the number .
Let us take an example.
Let there are a list of numbers.
1,3,8,6,5,8,2,9
We have to search if 5 is there in the list or not.
So, we start from the first element from 1.
then we see 3,8,6 and then find 5.
As soon as we find the search element 5 in the list we stop
searching,otherwise we continue the search upto the last
element.
Binary search
In binary search we always start from the middle elment and
compare the middle element to the search element.
If the search element is less than the middle element then
we go to the less half otherwise we go to the larger half.
In binary search the nos should be sorted in ascending
order at first.
Let us took an example of binary search.
Assume that we are reading a book.
The book has a huge volume.
let we have to find the page no 120 in this book.
The book has 200 pages approx.
Then we do not start looking for the page from the first
page, rather we look at the middle.
If the arbitrary page is 101 then we think that 120 paghe
is more than the 101 page so we go to the half which
contains more pages. So by using this method again and
again we can finally find out the page .
Is This Answer Correct ? | 86 Yes | 8 No |
Answer / asit kumsr tripathy
Linear search is ver easy and always search in sequential
way.
It starts searching from the first element upto the last
element until the search finds the number .
Let us take an example.
Let there are a list of numbers.
1,3,8,6,5,8,2,9
We have to search if 5 is there in the list or not.
So, we start from the first element from 1.
then we see 3,8,6 and then find 5.
As soon as we find the search element 5 in the list we stop
searching,otherwise we continue the search upto the last
element.
Binary search
In binary search we always start from the middle elment and
compare the middle element to the search element.
If the search element is less than the middle element then
we go to the lower half otherwise we go to the upper half.
In binary search the nos should be sorted in ascending
order at first.
Let us took an example of binary search.
Assume that we are reading a book.
The book has a huge volume.
let we have to find the page no 120 in this book.
The book has 200 pages approx.
Then we do not start looking for the page from the first
page, rather we look at the middle.
If the arbitrary page is 101 then we think that 120 paghe
is more than the 101 page so we go to the half which
contains more pages. So by using this method again and
again we can finally find out the page .
Is This Answer Correct ? | 31 Yes | 2 No |
Answer / kaloo
binary search is complex whle the linear search is more easy
Is This Answer Correct ? | 58 Yes | 32 No |
Answer / prabhjot singh
1.linear search is easy bt takes more time to search an
element as it compare all element sequentially...
2.elements r arranged randomly.
1. in binary search it start searching from middle, if the
searching element is not found in middle then it goes to
1/4,and vice versa..
and hence take less time than linear search.
2.elements r arranged in sorted orrder.
Is This Answer Correct ? | 32 Yes | 9 No |
Answer / greeshma and arya
time complexity of linear search is O[n] whereas that of binary search is O[logn].therefore binary search is faster than linear search.
Is This Answer Correct ? | 23 Yes | 4 No |
Answer / indrani chowdhury
1.linear search is easy bt takes more time to search an
element as it compare all element sequentially...
2.elements r arranged randomly.
1. in binary search it start searching from middle, if the
searching element is not found in middle then it goes to
1/4,and vice versa..
and hence take less time than linear search.
2.elements r arranged in sorted orrder.
Is This Answer Correct ? | 17 Yes | 3 No |
Answer / jeyachandran.p
Binary search is an efficient search compared to linear
search.Binary search requires sorted array while linear
search operates on unsorted array.
In binary search ,we looks through half of the list i.e
the element to be search is compared with mid value, if it
equals to mid value,search operation is over.otherwise if
the search element is smaller we have to search in the first
half of the list else we have to look in second half of the
list.
But linear search or sequential search requires an complete
search over the list.As far as ,Binary search is very best
in time and efficiency.It requires O[log n} times but linear
search requires O[n]times.
Is This Answer Correct ? | 14 Yes | 3 No |
Answer / anupama singh
| Binary search | Linear search |
-------------------------------------------------------------------------------------------------------------------------
1).Data must be in a sorted order | 1).Data any order
2).Time complexity is O(log n) | 2).Time complexity is O(n).
3).Only 1 "When" condition used | 3).Any no. of "When" condition used
4).Only "=" relation operator is used | 4).any relation operator is used
5).Access is faster | 5).Access is slow
6).Only single dimensional array used | 6).single/multi dimensional array used
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / amit kumar thakur
liner search -data is a linear array with (n)and item is
given this variable algorith find the location (loc)of item
in data. (linear search is used when the address is find)
(Aigorith)
step .1 [insert item at the end of data ]
set data [n+1]:=item
step. 2 set loc:=1
step.3 [search for item]
repeat while data [loc] is not equal to item
set loc :=loc+1
[end of loop]
step.4 if loc =n+1, then
set loc:=0
[end if]
step.5 EXIT.
Binary search
suppose data is an array which is store in increasing
numerical order .then there is a extremly effficient
searching called binary search .
which can be used to find the loc of a given item of
information in data.
e.g.
suppose one want to find the location of some name in a
telephone directory(or some word in a dictionry) then we
use the binary search not the linear search.
ALGORITH OF BINARY SEARCH.
STEP.1 SET BEG= LB, END=UB AND MID= INT.
STEP.2 BEG<=END AND DATA [MID]!ITEM
STEP.3 IF ITEM< DATA[MID], THEN:
set end:=mid-1
step.4 set mid=int[(beg+end)/2]
[end if]
step.5 EXIT.
Is This Answer Correct ? | 11 Yes | 5 No |
how to convert sapscript to email.....
what is the difference between select single * and slect upto 1 rows...
What are the two different ways of building a match code object? : abap data dictionary
6. what are the differences between scripts & smart forms?
What is the difference between scrolling a table horizontally and vertically?
In select-options, how to get the default values as current month first date and last date by default?
Did you use buffering?
what is meant by HIDE statement?
When is the top-of-page event triggered? : abap data dictionary
What are the different types of views and their definition?
Can we write inner join between transparent table and cluster table? If both having common fields?
I have 2 inputs in Module pool prgm, if i click on the input i need to get drop down list..How to get it..