Question 1Download the text file here. (Right click and save link as).
The goal of this problem are to implement a variant of the 2-sum algorithm (covered in the Week 6 lecture on hash table app lications).
The file contains 1 million integers, both positive and negative (there might be some repetitions!). This was your array of integers, with thei< Span id= "mathjax-span-5" class= "Texatom" > th row of the file specifying The i t h entry of the array.
Your task is to compute the number of target valuesTIn the interval [ -10000,10000] (inclusive) such that there isdistinctNumbers< Span id= "mathjax-span-21" class= "Mrow" >x ,y in the input file that Satisfy x+y< Span id= "mathjax-span-30" class= "Mo" >=t . (note:ensuring distinctness requires a one-line addition to the algorithm from lecture.)
Write Your numeric answer (an integer between 0 and 20001) in the space provided.
OPTIONAL Challenge:if This problem are too easy for your, try implementing your own hash table for it. For example, you could compare performance under the chaining and open addressing approaches to resolving collisions.
Answer for Question 1
Question 2Download the text file here.
The goal of this problem are to implement the ' Median Maintenance ' algorithm (covered in the Week 5 lecture on heap Applica tions). The text file contains a list of the integers from 1 to 10000 in unsorted order; You should treat the as a stream of numbers, arriving one by one. Lettingxi Denote theITh number of the file, thekTh medianmk is defined as the median of the numbersx1,... ,xk . (So, ifkis odd and thenmk Is((k+1)/2) th smallest number amongx1,... ,xk ; Ifkis even and thenmk is the(k/2) th smallest number amongx1,... ,xk .)
In the box below you should type the sum of these 10000 medians, modulo 10000 (i.e., only the last 4 digits). That's, you should compute(M1+m2+m3+? +m10000)mod10000 .
Programming Question-6