is the elements from mid 1 to high 10 Now how do we know when to stop the

Is the elements from mid 1 to high 10 now how do we

This preview shows page 4 - 6 out of 6 pages.

10.Now, how do we know when to stop the recursion? As we said earlier: 11.Binary Search implementation for an array of integers. ) { ) { ); 12. Binary search is incredibly fast. Suppose we have nitems in a list. It turns out that the maximumnumber ofiterations is log2n+1. Compare that to brute force search which on average takes n2iterations. As shownin the table below, the difference is astounding! 4
Image of page 4
5
Image of page 5
13. We stated above that when binary search returns a negative number this means the item was not found.Specifically, we wrote in the algorithm above that if the item was not found, we return:return -(low+1);What does this number mean? We can use it to tell us the index of where the key would belong in the list. For ); ); 6
Image of page 6

You've reached the end of your free preview.

Want to read all 6 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture