hw5-solns

# hw5-solns - amortized time of delete larger half S is | S |...

This preview shows page 1. Sign up to view the full content.

Illinois Institute of Technology Department of Computer Science Homework Assignment 5 Solutions CS 430 Introduction to Algorithms Spring Semester, 2009 1. Problem 17.1-2 on page 409 Solution: If a DECREMENT operation is added we can easily force the counter to change all bits per operation by calling DECREMENT and INCREMENT on 2 k - 1 . This gives a total running time of Θ( nk ) 2. Problem 17.3-7 on page 416 Solution: Taken an unordered linear list as data structure of S, Insert operation takes O(1) worst case time. To Fnd the median of S in O( | S | ) time, we use the worst case linear time median Fnding algorithm and delete its | s | 2 elements that are greater than or equal to the median. Therefore, we can assume the times of insert and delete larger half are at most 1 and | s | units respectively. The potential function can be deFned Φ( s )=2 | s | . The amortized time of insert operation will take 1 + ΔΦ = 1 + 2( | s | +1- | s | )= 3 = O(1). And for inserting m elements, it will take O(m) time cost. As well as, the
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: amortized time of delete larger half S is | S | +ΔΦ = | S | + 2( | s | 2-| s | ) = 0 = O(1). ±or deleting m elements larger than half , it will be O(m). 3. Problem 17.4-3 on page 425 Solution: Show that the amortized cost of TABLE-DELETE when α i-1 ≥ 1 / 2 is bounded above by a constant. Notice that the ith operation cannot cause the table to contract since contract only occurs when a i < 1 / 4. We need to consider cases for the load factor α i . ±or both cases num i = num i-1-1 and size i = size i-1 . Assume α i ≥ 1 / 2 ˆ c i = c i + Φ i- Φ i-1 = 1 + (2 · num i-size i ) - (2 · num i-1-size i-1 ) = 1 + (2 · num i-size i ) - (2 · ( num i + 1 -size i ) = -1 Then consider α i < 1/2 ˆ c i = c i + Φ i- Φ i-1 = 1 + (2 · num i-size i ) - ( size i-1 /2 -num i-1 ) = 3 · num i- 3/2 · size i + 2 = 3 α i · size i- 3/2 · size i + 2 < 3/2 · size i- 3/2 · size i + 2 = 2...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online