c3 Flashcards
(17 cards)
Why is the linear search also called “sequential search”?
Because it checks each element one by one in order.
If a linear search function is searching for a value that is stored in the last element of a 10,000-element array, how many elements will the search code have to read?
10,000 elements.
In an average case involving an array of N elements, how many times will a linear search function have to read the array to locate a specific value?
N/2 times.
A binary search function is searching for a value that is stored in the middle element of an array. How many times will the function read an element before finding the value?
Once.
What is the maximum number of comparisons that a binary search function will make when searching for a value in a 1,000-element array?
About 10 comparisons.
Why is the bubble sort inefficient for large arrays?
Because it repeatedly passes through the array, leading to many operations.
Why is the selection sort more efficient than the bubble sort on large arrays?
Because it minimizes swaps by selecting the correct element and moving it directly.
The __________ search algorithm steps sequentially through an array, comparing each item with the search value.
linear
The __________ search algorithm repeatedly divides the portion of an array being searched in half.
binary
The __________ search algorithm is adequate for small arrays but not large arrays.
linear
The __________ search algorithm requires that the array’s contents be sorted.
binary
If an array is sorted in __________ order, the values are stored from lowest to highest.
ascending
If an array is sorted in __________ order, the values are stored from highest to lowest.
descending
If data are sorted in ascending order, it means they are ordered from lowest value to highest value.
True
If data are sorted in descending order, it means they are ordered from lowest value to highest value.
False
The average number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found).
True
The maximum number of comparisons performed by the linear search on an array of N elements is N/2 (assuming the search values are consistently found).
False