

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Due: 11:55pm, May 3, 2009 (Sunday), no late submissions will be accepted (i.e., no late tokens can be used). You should finish this assignment independently. Any discussions or exchange of ideas is considered cheating. Problem I. (25 pts) Some of you are familiar with the problem of computing spatial distance histograms (SPH). The problem is stated as: given N points in a 2D space, draw a histogram of all point-to-point distances. A histogram can be described by three parameters: minimum distance l , maximum distance u , and resolution r. Therefore, such a histogram consists of the counts of pairwise distances that fall into ranges [ l , l+r ), [ l+r, l+2r ), [ l+2r, l+3r ), ….. Each such range is also called a bucket of the histogram. Let us assume we store the coordinates of all points in a database table with the following schema: points(point_ID, x_coordinate, y_coordinate) a (naïve) algorithm to solve the above problem is to calculate all point-to-point distances (note that there are N ( N - 1)/2 such distances to calculate) and determine which bucket each single distance belongs to, and increment the count of that bucket (by one). Your task is to write a PLPGSQL function that computes the SDH of all the points in a given “points” table. The function takes the maximum distance u , and resolution r as parameters. Here let us assume the minimum distance l is always 0 therefore there is no need to take it as another parameter. The output of the function should be something like this: Range | Count
[0, 10) | 100 [10, 20) | 122 [20, 30) | 79 ….. To get full credits for this problem, your code must compile and run in a PostgreSQL server with, of course, the correct outputs. I will read the code to award partial credits. In writing your function, you must follow the above schema of the “points” table. Problem II. Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, price) Write the following queries. For each query, it is stated in which query language you should express the query.