Programming Question-6

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.