7.13. Searching a Sorted Array with Array Method BinarySearch

Linear searches work well for small or unsorted arrays, but, for large unsorted arrays, linear searching is inefficient. If the array is sorted, the high-speed binary search technique can be used with class Array’s BinarySearch method. Our app that demonstrates method BinarySearch is nearly identical to the one in Fig. 7.14, so we show only the differences here. The complete code is located in the Fig07_15 folder with this chapter’s examples. The sample outputs are shown in Fig. 7.15. The GUI for this app is identical to the one in Fig. 7.13.

a) Creating random values to search

Image

Get Visual Basic® 2012 How to Program, Sixth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.