Results 1 to 4 of 4
  1. #1
    oglamaha is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default binary and lineary search

    consider an array storing the values 1 through 1000 in that order. Identify the sequence of probes that would be made in searching for the value 487 for both the linear and binary search. How many probes are there for the linear and binary search?

    That is the question. I have a binary and linear search programs but I cant seem to add a counter.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Is this a homework assignment?

    If it is, instead of my giving you the answer, I will direct you to learn the difference between linear and binary.
    algorithm - What is the difference between Linear search and Binary search? - Stack Overflow

    After reading and understanding the difference this problem is trivial.(this can be done very easily with pen and paper)

  3. #3
    oglamaha is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    it is a homework problem and i did work it out on paper and got 12 as the answer for the binary search but i just want to make sure that its correct

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Alright, manually code the binary search and have it return an int instead. each time it cuts in half you should increment the counter until the value is found, and when it is, simply return the counter.

Similar Threads

  1. Binary Search
    By cengho in forum Java Applets
    Replies: 4
    Last Post: 12-24-2010, 11:26 AM
  2. Binary Search Help
    By Plissken in forum New To Java
    Replies: 2
    Last Post: 03-13-2010, 11:34 AM
  3. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 02:42 AM
  4. Binary Search in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 08:43 PM
  5. binary search
    By tranceluv in forum New To Java
    Replies: 10
    Last Post: 01-14-2008, 08:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •