MIT6_851S10_assn07_sol

# MIT6_851S10_assn07_sol - 6.851 Advanced Data Structures...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.851 Advanced Data Structures (Spring’10) Prof. Erik Demaine Dr. Andr´ Schulz e Problem 7 TA: Aleksandar Zlateski Sample Solutions Finding the most signiﬁcant 1 bit. (a) � � We deﬁne C0 = 0b , and (C1 ) = 10b−1 Ax = x | (x + ~C1 ) & C1 Step-a(x) 1 Ax ← x + 01b−1 2 Ax ← Ax | x 3 return Ax & 10b−1 � � (b) Bx = (Ax >> (b − 1)) * (0b 1)b−1 >> (w − b) & 1b Steps-ab(x) 1 Ax ← Step-a(x) 2 Bx ← Ax >> (b − 1) 3 Bx ← (Bx * [0b 1]b−1 ) >> (w − b) 4 return Bx & 1b (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. Cx = b − (Bx & −Bx ) Steps-abc(x) 1 Bx ← Step-b(x) 2 Cx ← Bx & −Bx 3 return b − Cx � −1 (d) Let α = b=0 (1 << i) << i, then by setting y = (x >> Cx ) & 1b , and z = (y * [0b−1 1]b ) & α, i we have reduced the problem to parts (a)-(c). Full Algorithm Most-Significant(x) 1 Cx ← Steps-abc(x) 2 y ← (x >> Cx ) & 1b 3 z ← (y * [0b−1 1]b ) & α 4 Cz ← Steps-abc(z ) 5 return (Cx << b + Cz ) 1 MIT OpenCourseWare http://ocw.mit.edu 6.851 Advanced Data Structures Spring 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. ...
View Full Document

## This note was uploaded on 03/31/2011 for the course EECS 6.851 taught by Professor Erikdemaine during the Spring '10 term at MIT.

### Page1 / 2

MIT6_851S10_assn07_sol - 6.851 Advanced Data Structures...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online