For review Array and Big-O Review for Chapter 6 Test, question 11 (39)
If we trace the code with num = 20, how many times would the inner loop run?
While Delta < 40 Delta = 2, k = 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 → 10 Delta = 4, k = 2, 6, 10, 14, 18 → 5 Delta = 8, k = 4, 12, 20 → 3 Delta = 16, k = 8 → 1 Delta = 32, k = 16 → 1 10 + 5 + 3 + 1 + 1 = 20
Answer is C: O(n)
Note: you will not get this type of question tomorrow.
Solutions for the previous review:
2. D
3. C
4. B
5. C
6. E
7. C
8. A
9. C
10. B
11. D
Topics:
Arrays – Concepts and applications
ArrayLists
Searches: linear and binary – Concepts and tracing, Big-O, average, best and worse cases.
Sorts: Insertion and Selection – Concepts and tracing, Big-O, average, best and worse cases.
Study Guide:
Self-Review problems, T/F questions, MC questions and SA exercises.
Homework assignment from last Friday