binary and lineary search

• 03-27-2011, 09:43 PM
oglamaha
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.
• 03-27-2011, 09:47 PM
sunde887
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)
• 03-28-2011, 05:04 AM
oglamaha
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
• 03-28-2011, 05:38 AM
sunde887
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.