HW5_2009-20899 - Homework #5 Ilyong Cho(2009-20899) 11.1-1...

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

View Full Document Right Arrow Icon
Homework #5 Ilyong Cho(2009-20899) 11.1-1 Suppose that a dynamic set S is represented by a direct-address table T of length m . Describe a procedure that finds the maximum element of S . What is the worst-case performance of your procedure? Find the maximum elements of S by checking from T [ m - 1] to T [0] step by step. The first found element is the maximum element. If there aren’t any elements in the table T , then we must check all the slots. So the worst-case running time is Θ( n ) 11.3-3 Consider a version of the division method in which h ( k ) = k mod m , where m = 2 p - 1 and k is a character string interpreted in radix 2 p . Show that if string x can be derived from string y by permuting its characters, then x and y hash to the same value. Give an example of an application in which this property would be undesirable in a hash function. Suppose that string x is derived from string y by interchanging a pair of characters in positions a and b . Let x i be the i th character in x , and similarly for y i . We can view x as x = n 1 i =0 x i 2 ip , and y as y = n 1 i =0 y i 2 ip . So h ( x ) = ( n 1 i =0 x i 2 ip ) mod (2 p - 1), and h ( y ) = ( n 1 i =0 y i 2 ip ) mod (2 p - 1). ( h ( x ) - h ( y )) mod (2 p - 1) = 0 h ( x ) h ( y ) mod (2 p - 1) By the Euclidean algorithm, and 0 h ( x ) , h ( y ) 2 p - 1. Thus if we show that ( h ( x ) - h ( y )) mod (2 p - 1) = 0, then h ( x ) = h ( y ). h ( x ) - h ( y ) = ( n 1 ± i =0 x i 2 ip ) mod (2 p - 1) - ( n 1 ± i =0 y i 2 ip ) mod (2 p - 1) = ( n 1 ± i =0 x i 2 ip - n 1 ± i =0 y i 2 ip ) mod (2 p - 1) = (( x
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/26/2011 for the course ECE 366 taught by Professor Staff during the Spring '08 term at Michigan State University.

Page1 / 5

HW5_2009-20899 - Homework #5 Ilyong Cho(2009-20899) 11.1-1...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online