What is the prerequisite for using binary search on a list?单项选择题
A
The list must be unsorted
B
The list must contain only integers
C
The list must be of odd length
D
The list must be sorted
登录即可查看完整答案
我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。
类似问题
Binary Search Considering the following list. {12, 13, 15, 20, 23, 24, 25, 36, 40} What are the two first elements of the list that will be checked to find 25 using binary search? 1: The 1st element 2: The 2nd element
Given the following list of sorted elements, how many elements of the list will be checked to find 25 using binary search? {12, 13, 15, 20, 23, 24, 25, 36, 40}
What is the runtime complexity of the following code? NumberSearch(numbers, N, key) { mid = 0; low = 0; high = N - 1; while (high >= low) { mid = (high + low) / 2; if (numbers[mid] < key) low = mid + 1; else if (numbers[mid] > key) high = mid – 1; else return mid; } return -1; }
Given that: int[] list = {4,6,12,18,21,27,32,39,42,47,53,59,64,67,73}; and: int targetValue = 24; and given this Binary Search algorithm: public static int BinarySearch(int[] list, int targetValue) { int mid, low, high; low = 0; high = list.length - 1; while (high >= low) { mid = (high + low) / 2; if (list[mid] < targetValue) { low = mid + 1; } else if (list[mid] > targetValue) { high = mid - 1; } else { return mid; } } return -1; // not found } Which value in list will be the third to be compared to the targetValue in a binary search for the target value?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!