# sol7 - ← B x&-B x 3 return b-C x(d Let α = ∑ b-1 i...

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

6.851 Advanced Data Structures (Spring’10) Prof. Erik Demaine Dr. Andr´ e Schulz TA: Aleksandar Zlateski Problem 7 Sample Solutions Finding the most signiﬁcant 1 bit. (a) We deﬁne C 0 = 0 b , and ( C 1 ) = 10 b - 1 A x = ± x | ( x + ~ C 1 ) ² C 1 Step-a ( x ) 1 A x x + 01 b - 1 2 A x A x | x 3 return A x 10 b - 1 (b) B x = ( ( A x >> ( b - 1)) * (0 b 1) b - 1 >> ( w - b ) ) 1 b Steps-ab ( x ) 1 A x Step-a ( x ) 2 B x A x >> ( b - 1) 3 B x ( B x * [0 b 1] b - 1 ) >> ( w - b ) 4 return B x 1 b (c) Note that the order of the chunks has changed in part (b). We need to ﬁnd the least signiﬁcant 1 bit. Also, not that - x = ~ x + 1. C x = b - ( B x & - B x ) Steps-abc ( x ) 1 B x Step-b ( x ) 2 C x
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ← B x &-B x 3 return b-C x (d) Let α = ∑ b-1 i =0 (1 << i ) << i , then by setting y = ( x >> C x ) & 1 b , and z = ( y * [0 b-1 1] b ) & α , we have reduced the problem to parts (a)-(c). Full Algorithm Most-Significant ( x ) 1 C x ← Steps-abc ( x ) 2 y ← ( x >> C x ) & 1 b 3 z ← ( y * [0 b-1 1] b ) & α 4 C z ← Steps-abc ( z ) 5 return ( C x << b + C z ) 1...
View Full Document

## This note was uploaded on 01/20/2012 for the course CS 6.849 taught by Professor Erikdemaine during the Fall '10 term at MIT.

Ask a homework question - tutors are online