Lecture 12
Learning objectives
After this class, you should be able to:
- Define the terms: best case analysis, worst case analysis, average case analysis, and amortized analysis.
- Explain how amortized time complexity analysis differs from average time complexity analysis.
- Given an algorithm, give an input in which the best case behavior is observed, and derive its time complexity.
- Given an algorithm, give an input in which the worst case behavior is observed, and derive its time complexity.
- Given an algorithm and probabilities for possible inputs, derive its average case time complexity.
- Given a sequence of operations, derive the amortized time complexity for the sequence of operations.
Reading assignment
- Section 2.8 - 2.9( pages 66-67 only, for sec 2.9), class notes.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Instead of doubling the capacity of a vector each time that the current capacity is exceeded, assume that we increase the size of the array by
10
. What is the amortized time complexity for n
inserts?
- Given a sorted vector, what is the average number of array elements accessed during an insertion, assuming that there is an equal probability of insertion at any permissible position in the array? (Note: (i) The vector should be in sorted order after the insertion too. (ii) Assume that an insert does not cause the capacity to be exceeded.) (If group_number % 4 = 0)
- Given an unsorted vector, what is the worst case number of array elements accessed during a
push_back
operation? (Note: Assume that this operation does not cause the capacity to be exceeded.) (If group_number % 4 = 1)
- Given a vector, what is the average number of array elements accessed during a deletion, assuming that each element is equally likely to be deleted? (If group_number % 4 = 2)
- Given a vector, what is the average number of array elements accessed in checking for membership of a given key in the vector? Assume that the probability of the key not being in the vector is
1/n
, and all members of the vector are equally likely to be the key. (If group_number % 4 = 3)
- Questions on next lecture's material
- None.
Last modified: 30 Sep 2004