Computer Programming with C++ Chapter 9
If an array is sorted in this order, the values are stored from lowest to highest.
ascending
The __________________ can be used when we know the relative frequencies with which different inputs are likely to occur in practice. It uses these frequencies to form a weighted average of the number of steps performed on each input.
average case complexity
As the number of failed search attempts increase in a linear sech, so does the ___________________. The maximum number of comparisons is always N.
average number of comparisons
The _____ search algorithm requires that the array's contents be sorted.
binary
The __________ search algorithm repeatedly divides the portion of an array being searched in half.
binary
If an array is sorted in this order, the values are stored from highest to lowest.
descending
The elements in an array of a binary search are always ______________.
in order
The member variable being examined by search is sometimes called ___________ and the particular value being looked for is called the _________.
key field, search key
The _________ search algorithm is adequate for small arrays but not for large arrays.
linear
The _________ search algorithm steps sequentially through an array, comparing each item with the search value.
linear
Bubble sort places _________ numbers in place on each pass through the data.
one
Selection sort places ______ numbers in place on each pass through the data.
one
A _____________ is a method of locating a specific item in a collection of data.
search algorithm
Which sort usually requires fewer data values to be swapped, bubble or selection sort?
selection sort
Which sort usually requires fewer data values to be swapped, bubble sort or selection sort?
selection sort
Which sort, bubble sort or selection sort, would require fewer passes to sort a set of data that is already in the desired order?
selection sort
___________ algorithms are used to arrange data into some order.
sorting algorithms
To sort N numbers, bubble sort continues making passes through the array until ____________.
there were no number exchanges on the previous pass
One algorithm needs 10n basic operations to process an input size of n, and another algorithm needs 25n basic operations to process the same input. Which of the two algorithms is more efficient?
An algorithm with 10n basic operations is more efficient that which needs 25n basic operations. An algorithm which has less basic operations is more efficient than other algorithms.
REquires the values in the array to be sorted in order, starts searching at the element in the middle of the array. If the middle element's value is greater than the value being searched for, the algorithm next tests the element in the middle of the first half of the array. If the middle element's value is less than the value being searched for, the algorithm next tests the element in the middle of the last half of the array. Each time the array tests an array element and does not find the value being searched for, it eliminates half of the remaining portion of the array. This method continues until the value is found, or there are no more elements to test. This method is more efficient. Runs in O(logn) time.
Binary Search
Why is the selection sort more efficient than the bubble sort on large arrays?
Bubble sort normally has to make many data exchanges to place a value in its correct position. Selection sort determines which value belongs in the position currently being filled with the correctly ordered next value and then places that value directly there.
After one pass of selection sort, which value is in order?
First value is in order after completion of first pass of selection sort.
After one pass of bubble sort, which value is in order?
Last value is in order after completion of first pass
Uses a loop to step through each element of an array, comparing each element's value with the value being searched for. Runs in O(n) times.
Linear Search
2^n (n=whatever number you reach after exceeding the maximum given number)
Maximum number of comparisons in a binary search
The maximum number of comparisons performed by linear search to find an item in an array of N elements is?
N
The average number of comparisons performed by linear search to find an item in an array of N elements is __________.
N -- 2
In a binary search, after three comparisons have been made, only ___ of the array will be left to search.
N -- 6
A binary search will find the value it is looking for with just one comparison if that value is stored in the ________ array element.
N+1 ---- 2
To sort N numbers, selection sort makes _______ passes through the data.
N-1
A linear search will find the value it is looking for with just one comparison if that value is store in the ________ array element.
Oth
If a linear search is performed on an array, and it is known that some items are searched for more frequently than others, how can the contents of the array be reordered to improve the average performance search?
The items frequently searched for can be stored near the beginning of the array.
What is the worst-case complexity function of an algorithm?
The worst case complexity function f(n) of an algorithm is the number of steps it performs on an input size n that requires the most work. It give an indication of the longest time the algorithm will ever take to solve an instance of size n.
What does it mean to say that f(n) is in O(g(n))?
To say that f(n) is in O(g(n)) means that there exists a positive constant K such that f(n)=Kg(n) foa all n=1. This means that for large problem sizes, an algorithm with complexity function f(n) is no worse than one with complexity function g(n)
True or False: Any sort can be modified to sort in either ascending or descending order.
True (relational operators)