CARNEGIE MELLON UNIVERSITY

15-826 - Multimedia databases and data mining

Spring 2007

[SOLUTIONS] Homework 1 - Due: Tuesday Feb. 6, 1:30pm, in class.

For further questions or clarifications, please contact the TA.

Q1: SQL [30 pts]

  1. [10 pts] Find the single highest salary ever paid, and report the teamID, year and amount. In case of tie, report all tied entries.

  2. SELECT salary, teamID, year 
    FROM Salaries 
    WHERE salary = 
    	(SELECT MAX(salary) 
    	FROM Salaries);
    

    salaryteamIDyear
    26000000NYA2005


  3. [10 pts] Report the first and last name of all left-handed players who played for PIT in 1985.

  4. SELECT p.first_name, p.last_name 
    FROM PLAYERS p, SALARIES s
    WHERE s.teamID = 'PIT'
    	and s.year = 1985
    	and p.playerID = s.playerID
    	and p.rightHanded = 'L';
    

    Version using JOIN is also OK.

    first_namelast_name
    AndyHassler
    LarryMcWilliams
    JoeOrsulak
    RodScurry
    JasonThompson


  5. [10 pts] List the names of all stadiums the New York Yankees have ever played in.

  6. SELECT DISTINCT stadium 
    FROM Teams 
    WHERE teamName = 'New York Yankees';
    

    stadium
    Polo Grounds IV
    Shea Stadium
    Yankee Stadium I
    Yankee Stadium II


 

Q2: Z-order [10 pts]

  1. [2.5 pts] zorder should return the z-value of the given (x,y) point

    Pseudocode:
    z_value = zorder(x, y, n){
    	x_bits = make_binary(x)
    	y_bits = make_binary(y)
    	z_bits = ()
    	
    	if (length(x_bits) > n or length(y_bits) > n)
    		exit("input out of range")
    	
    	for bit_counter in 1:n {
    		z_bits = cat(z_bits, x_bits[bit_counter]
    		z_bits = cat(z_bits, y_bits[bit_counter]
    	}
    	
    	return(make_decimal(z_bits))
    }		
    
    Explanation:

    Make sure to check that input is in range of -n parameter. That is, x and y must be < 2^n in order to fit in the 2^n x 2^n grid. If so, make a new binary number by concatenating the first (leftmost) bit of the x-coordinate, then the first bit of the y-coordinate, then the second bit of the x-coordinate, and so on. Translate this number to base 10 and output.


  2. [2.5 pts] izorder should give the inverse.

    Pseudocode:
    (x_value, y_value) = izorder(z, n){
    	x_bits = ()
    	y_bits = ()
    	z_bits = make_binary(z)
    	z_bit_counter = 1
    	
    	for xy_bit_counter in 1:n{
    		x_bits = cat(x_bits, z_bits[z_bit_counter]
    		z_bit_counter++
    		y_bits = cat(y_bits, z_bits[z_bit_counter]
    		z_bit_counter++
    	}
    	
    	return(make_decimal(x_bits), make_decimal(y_bits))
    }		
    
    Explanation:

    Reverse the process above. Translate the input to binary, then put the first bit as the first bit of the x-coordinate, the second bit as the first bit of the y-coordinate, the third bit as the second bit of the x-coordinate, and so on. Translate the final x and y-coordinates to decimal and output.


  3. [2.5 pts] Give the results of your programs on this input file.

    commandargumentsoutput
    zorder-n 2 0 00
    zorder-n 3 0 11
    izorder-n 5 0(0,0)
    izorder-n 2 15(3,3)
    zorder-n 3 10 10Error: input is out of range (10 > 2^3)
    zorder-n 3 10 11Error: input is out of range (10 > 2^3)

  4. [2.5 pts] Using your izorder, plot a z-curve (perhaps using gnuplot) of order 7 (128x128 grid) and hand in the plot.

 

Q3: R trees [60 pts]