Comparing different runtimes
Binary search is described as having a runtime of O(log2 n). Part of the actual runtime of a binary sort is the procedure linkage that transfers control to the sort routine and the return that transfers control back to the calling routine. These can be considered to take a fixed time. A more detailed estimate of the runtime of a binary search is K + Mxceil(log_2(N+1)), where N is the input size, K represents the time to do the calling sequence, and M is a multiplier to account for how long each step takes. What can you say about this estimate?
For different implementations, K and M may be different.
Suppose that you have two sort algorithms, that they are called A and B, and that the growth of A is O(n2) and B is O(n log_2(n)), where n is the number of elements to be sorted. Which of the following statements is true?
If n is doubled, algorithm B will take a little more than twice as long.
Binary search is described as having a runtime of O(log2 n). Suppose that you are designing a program that requires a search of a sorted array as one of its steps. And further, there is a system-supplied binary search routine that is available. Which of the following factors might make you prefer to use an inline linear search instead?
The array to be searched is small. - or - The system routine must be paged in at the cost of several milliseconds each time. - or - You expect that your software will be ported to different environments, not all of which will have a compatible system search routine.
Which one of the following sorts has the same big O notation as a merge sort?
Quick sort
What is the runtime for listing the subsets of a set having 10 elements?
1024
What is the big O notation for a linear search having 2,048 elements in the array?
2048
What is the big O notation of a merge sort having 2,048 elements in the array?
22,528
What is the runtime for listing the order of sitting 10 people in a conference room that has 10 seats?
3628800
How many times faster does a quick sort perform on an array of size 16 entries compared to a corresponding selection sort?
4
What is the big O notation for a selection sort having 2,048 elements in the array?
4194304
What is the big O notation for a factorial algorithm that has a size of problem of 12?
479001600
Which one of the following number of elements within a set produces 512 subsets?
9
Binary search is described as having a runtime of O(log2 n). Suppose that you have an array of size 15. How many comparisons will a binary search need to make to determine the location of an element x or that x is not in the array?
At most, 4
Binary search is described as having a runtime of O(log_2 n). Suppose that you have an array of size 15. How many comparisons will a binary search need to make to determine the location of an element x or that x is not in the array?
At most, 4
Binary search is described as having a runtime of O(log2 n). Suppose that you have an array of size 16. How many comparisons will a binary search need to make to determine the location of an element x or that x is not in the array?
At most, 5
Which one of the following is the fastest algorithm in terms of operation?
Constant
Which one of the following algorithms most likely has a nested loop having three "for" loops?
Cubic
Bubble sort has time complexity O(n^2)and quicksort has time complexity O(n log_2(n)). For small input sizes, what does this tell you.
Not much. Either method might be faster.
Which one of the following describes the big O notation for a quick sort?
O(n *log_2 n)
Bubble sort has time complexity O(n^2)and quicksort has time complexity O(n log_2(n)). If you think of n getting bigger and bigger, what does this tell you?
The ratio of the runtime of bubble sort to quick sort is approximately D*(n/log n) for some constant D. - or - Bubble sort runtime will be approximately B*n^2 for some constant B.
Binary search is described as having a runtime of O(log n). Suppose that you have a fragment of code that calls a binary search function that will either return the index of the element in the array or -1 if the element is not found. The first parameter is the array A, the second is the size of A, and the third is the item being searched for. ndx = bin_search(A, n, x); if (ndx == -1) /* not found */ else /* found */ Which of the following is included in the runtime of bin_search()?
The steps required to return the value and control to the calling routine - or - The procedure call sequence
Bubble sort has time complexity and quicksort has time complexity . Time complexity means how long the algorithm will take to complete for a given input size. There is an analogous concept of space complexity, which is how much memory will be required to complete the computation for a given input size. One error when working with big O notation is forgetting what it means. Thus, saying that bubble sort has runtime means that there is a constant M and a value n0, and if n > n0, then the runtime will be bounded by . That error takes the form of saying the runtime of bubble sort is n2, or . There is another error here as well. What is it?
The time units are missing. - or - Is that n2 seconds, n2 milliseconds, or n2 microseconds?
Let f(n) = e^n g(n) = n^n h(n) = n! Put the following is order in terms of growth from smallest to largest.
f g h