This preview shows page 1. Sign up to view the full content.
Unformatted text preview: n/ 2 . In that case, the of this algorithm (and any similar divideandconquer algorithm) is: T ( n ) = 4 T ( n/ 2) + O ( n ) = O ( n 2 ) . 7.14 (a) For 3 values, use the following series of if statements (based on the decision tree concept of Figure 8.16, and optimized for swaps). void Sort3(ELEM A) { // Assume A has 3 elements if (A[1] < A[0]) if (A[2] < A[0]) if (A[2] < A[1]) // ZYX swap(A[0], A[2]); else { // YZX swap(A[0], A[1]); swap(A[1], A[2]); } else // YXZ swap(A[0], A[1]); else if (A[2] < A[1]) if (A[2] < A[1]) { // ZXY swap(A[0], A[2]); swap(A[1], A[2]); } else // XZY swap(A[1], A[2]); else // XYZ  Do nothing } Cost:...
View
Full
Document
This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.
 Fall '08
 BELL,D

Click to edit the document details