11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 14.5 Exercises 48114.14 For the following recurrence, give a closed-form solution. You should notgive an exact solution, but only an asymptotic solution (i.e., using Θ not<strong>at</strong>ion).You may assume th<strong>at</strong> n is a power of 2. Prove th<strong>at</strong> your answer iscorrect.T(n) = T(n/2) + √ n for n > 1; T(1) = 1.14.15 Using the technique of exp<strong>and</strong>ing the recurrence, find the exact closed-formsolution for the recurrence rel<strong>at</strong>ionT(n) = 2T(n/2) + n; T(2) = 2.You may assume th<strong>at</strong> n is a power of 2.14.16 Section 5.5 provides an asymptotic analysis for the worst-case cost of functionbuildHeap. Give an exact worst-case analysis for buildHeap.14.17 For each of the following recurrences, find <strong>and</strong> then prove (using induction)an exact closed-form solution. When convenient, you may assume th<strong>at</strong> n isa power of 2.(a) T(n) = T(n − 1) + n/2 for n > 1; T(1) = 1.(b) T(n) = 2T(n/2) + n for n > 2; T(2) = 2.14.18 Use Theorem 14.1 to prove th<strong>at</strong> binary search requires Θ(log n) time.14.19 Recall th<strong>at</strong> when a hash table gets to be more than about one half full, itsperformance quickly degrades. One solution to this problem is to reinsertall elements of the hash table into a new hash table th<strong>at</strong> is twice as large.Assuming th<strong>at</strong> the (expected) average case cost to insert into a hash table isΘ(1), prove th<strong>at</strong> the average cost to insert is still Θ(1) when this re-insertionpolicy is used.14.20 Given a 2-3 tree with N nodes, prove th<strong>at</strong> inserting M additional nodes requiresO(M + N) node splits.14.21 One approach to implementing an array-based list where the list size is unknownis to let the array grow <strong>and</strong> shrink. This is known as a dynamic array.When necessary, we can grow or shrink the array by copying the array’s contentsto a new array. If we are careful about the size of the new array, thiscopy oper<strong>at</strong>ion can be done rarely enough so as not to affect the amortizedcost of the oper<strong>at</strong>ions.(a) Wh<strong>at</strong> is the amortized cost of inserting elements into the list if the arrayis initially of size 1 <strong>and</strong> we double the array size whenever the numberof elements th<strong>at</strong> we wish to store exceeds the size of the array? Assumeth<strong>at</strong> the insert itself cost O(1) time per oper<strong>at</strong>ion <strong>and</strong> so we are justconcerned with minimizing the copy time to the new array.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!