Array Sorting/Searching
private int[ ] a = {-10, -5, 1, 4, 8, 30}; public void doubleLast() { for (int i = a.length / 2; i < a.length; i++) { a[i] = a[i] * 2; } } What will execute?
-10, -5, 1, 8, 16, 60
private int[ ] a = {-10, -5, 1, 4, 8, 30}; public void doubleLast() { for (int i = a.length; i < a.length; i++) { a[i] = a[i] * 2; } }
-20, -10, 2, 8, 16, 60
int[] nums = {5,2,8,9,1,6,3}; Arrays.sort(nums); int loc = Arrays.binarySearch(nums,15); What is the output?
-8
int[] nums = {5,2,8,9,1,6,3}; Arrays.sort(nums); int loc = Arrays.binarySearch(nums,2); What is the output?
1
int[] nums = {5,2,8,9,1,6,3}; Arrays.sort(nums); int loc = Arrays.binarySearch(nums,8); What is the output?
5
___________ algorithms are used to arrange random data into some order. a. Standard search b. Linear c. Sorting d. Binary search e. None of these
Sorting
The _________ is adequate for searching through small arrays. a. binary search b. linear search c. unary search d. bubble sort e. None of these
b. linear search
A(n) ________ search is more efficient than a(n) ________ search a. character, string b. integer, double c. binary, linear d. linear, binary e. None of these
binary, linear
When an array is sorted from highest to lowest, it is said to be in _____ order. a. reverse b. forward c. descending d. ascending d. None of these
descending
Data that is sorted in ascending order is ordered a. from lowest to highest value b. from highest to lowest value c. always with a binary sort algorithm d. always with a linear sort algorithm e. None of these
from lowest to highest value
A binary search begins with the _________ element of an array. a. first b. last c. largest d. middle e. None of these
middle
The advantage of a linear search is its ____________. a. complexity b. efficiency c. simplicity d. speed e. None of these
simplicity
Array elements must be _________ before a binary search can be performed. a. summed b. set to zero c. sorted d. positive numbers d. None of these
sorted
int[] nums = {5,2,8,9,1,6,3}; Arrays.sort(nums); int loc = Arrays.binarySearch(nums,7); What is the output?
-6
A ________ algorithm is a method of locating a specific item of information in a larger collection of data. a. sort b. search c. standard d. linear e. None of these
search