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
 Fall '08
 BELL,D
 undifferentiated bolts

Click to edit the document details