# Serial and binary search in java algorithm

O n Example Python Code: If you do not mark the already tried ones, this can become worse. The table must be sorted for binary search. A linear search looks down a list, one item at a time, without jumping. Smaller, look further on.

Think of it as two different ways of finding your way in a phonebook. Pick a random name "Lastname, Firstname" and look it up in your phonebook. As an example, suppose you were looking for U in an A-Z list of letters index ; we're looking for the value at index

Failing that, a general wikipedia, c2 or google search can answer may of these sort of questions. Or if there is no value in the array finishes the search. This means that we only need to look at the left part of the data.

But if you will be performing many searches say at least O log n searchesit may be worthwhile to sort the data so that you can perform binary searches. If it is greater, gets the right part of the array. This means that we only need to look at the left part of the data.

I would like to add one difference- For linear search values need not to be sorted. Think of it as two different ways of finding your way in a phonebook. May 4 '09 at

A binary search is when you start with the middle of a sorted list, and see whether that's greater than or less than the value you're looking for, which determines whether the value is in the first or second half of the list. A binary search comes with the prerequisite that the serial and binary search in java algorithm must be sorted. Linear Search looks through items until it finds the searched value. Mia Clarke 6, 3 41 But for binary search the values must be in sorted order.