ps4 - Introduction to Algorithms Massachusetts Institute of...

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

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

Unformatted text preview: Introduction to Algorithms Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser March 11, 2004 6.046J/18.410J Handout 12 Problem Set 4 This problem set is due in recitation on Friday, March 19. Reading: Chapters 30.1-30.2, 11.1-11.3, 11.5, 12.1-12.3 There are three problems. Each problem is to be done on a separate sheet (or sheets) of paper. Mark the top of each sheet with your name, the course number, the problem number, your recitation section, the date, and the names of any students with whom you collaborated. You will often be called upon to "give an algorithm" to solve a certain problem. Giving an algorithm entails: 1. A description of the algorithm in English and, if helpful, pseudocode. 2. A proof (or argument) of the correctness of the algorithm. 3. An analysis of the running time of the algorithm. It is also suggested that you include at least one worked example or diagram to show more precisely how your algorithm works. Remember, your goal is to communicate. Graders will be instructed to take off points for convoluted and obtuse descriptions. If you cannot solve a problem, give a brief summary of any partial results. Problem 4-1. Electric Potential of Equally Spaced Charges 1 2 3 4 5 6 # In this problem we would like to find the electric potential at each point charge all other point charges, given by the formula where is a constant: induced by " '(& % ! 4# 0 5321) VITRS IP UW Q F$ 6 # GF H 6 % 4# 0 BA@987) E CD #$ # Consider a set of respectively. Each following figure: point charges located at position carries an electric charge . This configuration with along the -axis is depicted in the 7 2 Handout 12: Problem Set 4 (a) The induced potential on all the point charges can be computed by multiplying an matrix by the -dimensional charge vector . In other words , where is the constant in the above formula. Give the matrix for . What is 's form in general? (c) Give an algorithm that computes the potential vector , in Problem 4-2. Universal Hashing Recall that a collection of hash function from a universe for all in we have to a range is called universal if For any boolean matrix and any -bit vector we define the function as , where by this we mean the usual matrix-vector multiplication and the usual vector addition, except that all the operations are done modulo 2. For example, if and we have (a) Prove that the collection (b) Let choose with is universal. be the set we would like to hash. Let and . Prove that if we from uniformly at random, the expected number of pairs and is . with size , where in expected time and . Give a randomized space. (c) Let and be subsets of algorithm for finding Problem 4-3. Range Query in Binary Search Tree Given a binary search tree and a pair of numbers with , give an algorithm that returns the set of elements in with key values in . Your algorithm should run in time, where is the height of and is the number of elements within the range. % (% $ 4 4 m0 f 4 f 9m0 4 Whk0 e l i B g f e jX % v h% f 4 4 P H % 4 P H % d 0 20 R Qs0 A1@"0 R QY0 R Q0" PY H 9 @"0 4 B (% v % 8CX15GUC9 16F R QQ0 % B 8 7 I I @ B 8 7 5 S P H 5 p xw p a f XWv Q" yT" % f 7 a Q" % 4 P H rqUW " f 7 A15"0 R ts0 xXWv BauQ" au " w p e e T" CiD 7 e v a 00 $ We want to implement universal hashing from to (where VW@U915 STR QI0 8 7 PH D E 4 0 G $ BC9 15A%( '8916% 8 7 @ 75 3 4 2 0 A1@"0 % 4 rqUW " T" p Q" 6 % G o qpn CiD I I % " % 4 1 0 f h7 G n e 3 rG n ( % f G g 7 4 0 (b) Give a representation of by an -size vector. time. 6 % % 0 1()& $ "'%# ! 7 e F v % e Gcb" F`%A1"@0 R QHY0 CX15 a 4 P B87 )$ F e e " % 6 0 ). d ...
View Full Document

Ask a homework question - tutors are online