Ch 19x2 Final Exam, Chapter 19 Quiz
A search on a data set that divides the data roughly in half every iteration is called a(n) _____ search A. binary B. sequential C. divided D. sorted
Binary
Given the following array, show the comparisons to an array entry that are performed to search for the number 23 if you use the binary search algorithm. 2 3 5 7 11 13 17 19 23 29 31 37
**First comparison:** Midpoint is 17. Since 23 is greater than 17, focus on the right half. **Second comparison:** Midpoint is 29. Since 23 is less than 29, focus on the left half. **Third comparison:** Midpoint is 23. We found the number 23.
In a recursive sequential search of an unsorted array we search elements from 0 to n-1 1 to n 0 to n 1 to n-1
0 to n-1
Given the following array, how many comparisons to an array entry are performed to search for the number 13 if you use the binary search algorithm? 2 3 5 7 11 13 17 19 23 29 31 37 A. 12 B. 1 C. 2 D. 6
1
Given the following array, how many comparisons to an array entry are performed to search for the number 11 if you use the binary search algorithm? 2 3 5 7 11 13 17 19 23 29 31 37 A. 10 B. 7 C. 2 D. 5
7
All objects have the method compareTo True or False
False
An empty array can never be a base case for a recursive search algorithm because it never contains the desired item True or False
False
An empty array can never be a base case for a recursive search algorithm because it never contains the desired item True False
False
The average-case time efficiency of a binary search on a sorted array is A. O(1) B. O(log n) C. O(n) D. O(n2)
O(log n)
The average-case time efficiency of a sequential search on an unsorted chain of linked nodes is O(1) O(n2) O(log n) O(n)
O(n)
What is the difference between the calculation of the midpoint in the Java computation and the one given in the binarySearch method? Show the impact, if any on a search between the indexes 26 and 50.
The primary difference is that binarySearch method searches a subrange in the array. In addition, BinarySearch uses indices of elements.The method starts with the middle index of array and searches for desired entry. It reduces amount of comparisons by cutting the problem in half--> into smaller problems of the array to search.In java computation midpoint it adds first and last and divides by 2 to find midpoint but still go through full steps to find desired array. binary Search between 26 and 50 if we are searching for 41 our midpoint is 38. we can cut the problem by saying 38 is less than 41 don't search this half. Now we have reduced number of comparison steps
A sequential search can be more efficient if the data is sorted True or False
True
You can implement a recursive sequential search of a chain of linked nodes with the same efficiency as that of a sequential search of an array True or False
True
You can implement an iterative sequential search of a chain of linked nodes with the same efficiency as that of a sequential search of an array True or False
True
Given the following array, show the comparisons to an array entry that are performed to search for the number 23 if you use the binary search algorithm. 2 3 5 7 11 13 17 19 23 29 31 37
apply formula: 0 + = 11 . 11/2 = 5 . entry at index 5 is 13we are searching for 23. we know 13 is less than 23 so ignore the first half before 13. search after 13 because 13<23 now next entry is 17, 19 and then 23. faster and more efficient search while reducing comparisons.
A binary search is usually much faster than a sequential search on unsorted data stored in a chain of linked nodes True False
false
A binary search is usually slower than a sequential search on sorted array of data True False
false
In a sequential search of a sorted array, you must examine the entire array if an item is not present in the array True False
false
You use fewer comparisons in a recursive search than a sequential search on an unsorted array True False
false
A sequential search of a sorted array can tell whether an item is present in the array in _____ a sequential search of an unsorted array. A. more comparisons than B. none of the choices C. fewer comparisons than D. the same number of comparisons as
fewer comparisons than
What is the base case in the recursive algorithm for a binary search of a sorted array? A. first index > last index B. the array is empty C. first index == last index D. first index < last index
first index > last index
The implementation of the ADT list method contains is dependent on A. how we store the list entries B. how we handle empty lists C. whether the list entries are in ascending order D. whether the list entries are in descending order
how we store the list entries
A binary search of a sorted chain of nodes is _____ than a sequential search of a sorted chain. faster less efficient more efficient easier to implement
less efficient
A binary search of a sorted chain of nodes is _____ than a sequential search of a sorted chain. less efficient easier to implement more efficient faster
less efficient
A sequential search can be ______ if the data is sorted. A. impossible B. less efficient C. more efficient D. a bad choice
more efficient
A sequential search can be more efficient if the data is sorted True False
true
A sequential search on a very large array is very inefficient True False
true
If you have a list object to search that is an instance of ADT list, you search it by using the list operation contains True False
true
You can implement an iterative sequential search of a chain of linked nodes with the same efficiency as that of a sequential search of an array True False
true
What is the difference between the calculation of the midpoint in the Java computation and the one given in the binarySearch method? Show the impact, if any on a search between the indexes 26 and 50.
In midpoint java calculation what actually happens is we take two numbers and in order to calculate the midpoint we add both number and divide by two and by doing so we get the midpoint But in the binary search , it is array based searching.by using the index starting from start and last index we divide index and reach at the the half of the array and then compare the value at that indexIf there is need to search in between the index 26 and 50, Binary search will be the best option here.
