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.

Results 1 to 6 of 6

Thread: Which one the best method use for Search..?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Which one the best method use for Search..?

    please tell my anyone which one the best method use for searching. linear, binary etc.

    thnxx


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Which one the best method use for Search..?

    It depends. What are you searching? How much data is there to search through?

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    11
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Which one the best method use for Search..?

    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.

  4. #4

    Default Re: Which one the best method use for Search..?

    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.

  5. #5
    Junior Member
    Join Date
    Nov 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Which one the best method use for Search..?

    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.

  6. #6
    Junior Member
    Join Date
    May 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Which one the best method use for Search..?

    Thank you for sharing

Similar Threads

  1. Replies: 1
    Last Post: January 23rd, 2013, 07:29 AM
  2. Binary Search Tree Lookup Method
    By Sbonett in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 15th, 2012, 07:43 AM
  3. Graph Search Theory with extend of BFS, UFS and A* Search in grid
    By keat84 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 7th, 2012, 09:46 AM
  4. Array Search Method
    By Kyuubi426 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2011, 08:31 PM
  5. Trouble with Binary Search on Insert Method
    By EricSt in forum Algorithms & Recursion
    Replies: 1
    Last Post: February 17th, 2010, 10:34 PM