Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

PRACTICE TEST

Chapter 10: Algorithms and Time Complexity

INSTRUCTIONS: Answer each question below. Once you finish taking the test, check
the answers provided in the Answer Key at the end of this test.

1. Which of the functions f(x) = 100x, g(x) = 10x2, or h(x) = (1.02)x will eventually be
the largest?
A: f(x)
B: g(x)
C: h(x)
D: cannot be determined

2. If f(n) is a real valued function then f(n) is:


A: O(f(n))
B: (f(n))
C: (f(n))
D: all of the above

3.
Suppose f(n) is an eventually non-decreasing function where f(1) = d, f(n) = af( )
+ cnk, if n > 1 and n = bm, where m is a positive integer, b  2, k  0 are constant
integers, and a > 0, c > 0, and d  0 are constants. If a < bk then f(n) is
A: (nk)
B: (nklg n)
C: (nlogba)
D: none of the above

Suppose f(n) is an eventually non-decreasing function where f(1) = d, f(n) = af( )


4.
+ cnk, if n > 1 and n = bm, where m is a positive integer, b  2, k  0 are constant
integers, and a > 0, c > 0, and d  0 are constants. If a = bk then f(n) is
A: (nk)
B: (nklg n)
C: (nlogba)
D: none of the above

©2010 Cengage Learning Asia Pte Ltd


5.
Suppose f(n) is an eventually non-decreasing function where f(1) = d, f(n) = af( )
+ cnk, if n > 1 and n = bm, where m is a positive integer, b  2, k  0 are constant
integers, and a > 0, c > 0, and d  0 are constants. If a > bk then f(n) is
A: (nk)
B: (nklg n)
C: (nlogba)
D: none of the above

6. Let f(n) = 2 + 4 + 6 + ... + 2n, n  1. Then f(n) is


A: (n2)
B: (n)
C: (nlg n)
D: none of the above

7. Let n  1 then n! is
A: (n2)
B: (n)
C: (nlg n)
D: none of the above

8. Suppose that f(n) = n3 + nlg n, then f(n) is:


A: (n3)
B: (n)
C: (nlg n)
D: none of the above

9. Suppose that f(n) is O(n2) and g(n) is O(n3), then f(n) + g(n) is
A: O(n)
B: O(n2)
C: O(n3)
D: none of the above

10. Define the relation R on the set of nonnegative real valued functions by f R g if

©2010 Cengage Learning Asia Pte Ltd


and only if f(n) = (g(n)). Then R is
A: an equivalance relation
B: a poset
C: a lattice
D: none of the above

For exercises 11 through 13, Let L be the list of elements 35, 45, 15, 20, 95, 50.
Suppose that sequential search is used.

11. How many comparisons are required to determine if 38 is in L?


A: 2
B: 4
C: 6
D: none of the above

12. How many comparisons are required to determine if 20 is in L?


A: 2
B: 4
C: 6
D: none of the above

13. How many comparisons are required to determine if 95 is in L?


A: 2
B: 4
C: 6
D: none of the above

For exercises 14 through 16, Let L be the list of elements 35, 45, 55, 60, 75, 95, 100.
Suppose that binary search is used.

14. How many comparisons are required to determine if 95 is in L?


A: 1
B: 2
C: 3

©2010 Cengage Learning Asia Pte Ltd


D: none of the above

15. How many comparisons are required to determine if 35 is in L?


A: 1
B: 3
C: 5
D: none of the above

16. How many comparisons are required to determine if 65 is in L?


A: 1
B: 2
C: 3
D: none of the above

For exercises 17 through 19, Let L be the list of elements 35, 45, 15, 20, 95, 50.
Suppose that selection sort is used.

17. What is the first element placed in the "sorted" list?


A: 35
B: 95
C: 15
D: none of the above

18. How many comparisons are required to place the first element in the "sorted"
list?
A: 3
B: 5
C: 7
D: none of the above

19. How many comparisons are required to place the third element in the "sorted"
list?
A: 3
B: 5
C: 7

©2010 Cengage Learning Asia Pte Ltd


D: none of the above

For exercises 20 through 22, Let L be the list of elements 15, 20, 45, 30, 95, 50.
Suppose that insertion sort is used and the first two keys are in order.

20. To move 45 to the correct position, how many comparisons are required?
A: 1
B: 3
C: 5
D: none of the above

21. Now assuming the first three keys are in order, how many comparisons are
required to move 30 to the correct position?
A: 2
B: 3
C: 5
D: none of the above

22. When the first five keys are in order, to place 50 will require how many
comparisons?
A: 2
B: 3
C: 5
D: none of the above

For exercises 23 through 25, let L1 be the list of elements 2, 4, 7, 8, 18 and let L2 be
the list of elements 3, 5, 9, 11, 20, 22, 25. Suppose that merge sort is used.

23. How many comparisons are required to place the first element in the "sorted"
list.
A: 1
B: 2
C: 3
D: none of the above

©2010 Cengage Learning Asia Pte Ltd


24. How many comparisons are required to merge the two lists?
A: 5
B: 9
C: 12
D: none of the above

25. How many comparisons are required to place the second element in the "sorted"
list.
A: 1
B: 2
C: 3
D: none of the above

26. In the worst case, which of the following sorts is not O(n2)?
A: insertion
B: selection
C: bubble
D: none of the above

27. In the best case insertion sort is big-O of


A: n
B: nlg n
C: n2
D: none of the above

28. Is binary search always a better choice than sequential search?


A: yes, always
B: no, the list must be sorted before binary search can be used
C: no, only for large lists
D: none of the above
29. Using Strassen’s method of matrix multiplication for a 2X2 matrix the number of
scalar multiplications and additions required are respectively:
A: 8 and 4
B: 7 and 10

©2010 Cengage Learning Asia Pte Ltd


C: 7 and 18
D: none of the above

30. If A is a 2x4 matrix, B is a 4x5 matrix, C is a 5x3 matrix, and D is a 3x7 matrix,
what is the optimal number of scalar multiplications required to compute
ABCD?
A: 105
B: 112
C: 144
D: none of the above

©2010 Cengage Learning Asia Pte Ltd


Answers:

1. C 2. D 3. A 4. B 5. C 6. A 7. C 8. A 9. C 10. A
11. C 12. B 13. D 14. C 15. C 16. D 17. C 18. B 19. A 20. A
21. A 22. A 23. A 24. B 25. B 26. D 27. A 28. B 29. C 30. B

©2010 Cengage Learning Asia Pte Ltd

You might also like