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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.