You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Write a function to calculate all possible assignment vectors of 2n users, where n users are assigned to group 0 (control), and n users are assigned to group 1 (treatment).
Recursive programming (sol in code)
defn_choose_k(n, k):
""" function to choose k from n """ifk==1:
ans= []
foriinrange(n):
tmp= [0] *ntmp[i] =1ans.append(tmp)
returnansifk==n:
return [[1] *n]
ans= []
space=n-k+1foriinrange(space):
assignment= [0] * (i+1)
assignment[i] =1forcinn_choose_k(n-i-1, k-1):
ans.append(assignment+c)
returnans# test: choose 2 from 4print(n_choose_k(4, 2))
2. Given a list of tweets, determine the top 10 most used hashtags.
Store all the hashtags in a dictionary and use priority queue to solve the top-k problem
An extension will be top-k problem using Hadoop/MapReduce
3. Program an algorithm to find the best approximate solution to the knapsack problem in a given time.
5. You have a stream of data coming in of size n, but you don’t know what n is ahead of time. Write an algorithm that will take a random sample of k elements. Can you write one that takes O(k) space?
11. Describe the difference between primary keys and foreign keys in a SQL database.
Primary keys are columns whose value combinations must be unique in a specific table so that each row can be referenced uniquely.
Foreign keys are columns that references columns (often primary keys) in other tables.
12. Given a COURSES table with columns course_id and course_name, a FACULTY table with columns faculty_id and faculty_name, and a COURSE_FACULTY table with columns faculty_id and course_id, how would you return a list of faculty who teach a course given the name of a course?
SELECTf.faculty_nameFROM COURSES c
JOIN COURSE_FACULTY cf
ONc.course_id=cf.course_idJOIN FACULTY
ONf.faculty_id=cf.faculty_idWHEREc.course_name= xxx;
13. Given a IMPRESSIONS table with ad_id, click (an indicator that the ad was clicked), and date, write a SQL query that will tell me the click-through-rate of each ad by month.
SELECT ad_id, MONTH(date), AVG(click)
FROM IMPRESSIONS
GROUP BY ad_id, MONTH(date);
14. Write a query that returns the name of each department and a count of the number of employees in each:
EMPLOYEES containing: Emp_ID (Primary key) and Emp_Name
EMPLOYEE_DEPT containing: Emp_ID (Foreign key) and Dept_ID (Foreign key)
DEPTS containing: Dept_ID (Primary key) and Dept_Name
SELECTd.Dept_Name, COUNT(*)
FROM DEPTS d
LEFT JOIN EMPLOYEE_DEPT ed
ONd.Dept_ID=ed.Dept_IDGROUP BYd.Dept_Name;