please tell my anyone which one the best method use for searching. linear, binary etc.
thnxx
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
please tell my anyone which one the best method use for searching. linear, binary etc.
thnxx
It depends. What are you searching? How much data is there to search through?
Re: Which one the best method use for Search..?
Searching is an important function in computer science. As the data sets become larger and larger, good search algorithms will become more important. At one point in the history of computing, sequential search was sufficient. But that quickly changed as the value of computers became apparent.
Linear search has many interesting properties in its own right, but is also a basis for all other search algorithms. Learning its working is critical.
Binary search is the next logical step in searching. Performance can be improved significantly when the data set is very large by using interpolation search, and improved yet again by using binary search when the data set gets smaller.
Searching for data is one of the fundamental fields of computing. Often, the difference between a fast program and a slow one is the use of a good algorithm for the data set.
Binary search is a more efficient search algorithm which relies on the elements in the list being sorted. We apply the same search process to progressively smaller sub-lists of the original list, starting with the whole list and approximately halving the search area every time.
In general, the simplest methods are the best. For example:
public static int search(int arr[], int x)
{
int n = arr.length;
for (int i = 0; i < n; i++)
{
if (arr[i] == x)
return i;
}
return -1;
}
The question is how much you care about performance. If you have a closed system, for example raspberry pi 4, then you have to analyze different search methods for each method and choose the most optimal one. If you are not limited by resources, sometimes it is worth writing something that is clearer than more efficient. Unfortunately, there is no golden advice for this.
Thank you for sharing