CSE 344 Midterm. Monday, Nov 4, 2013, 9:30-10:20. Question Points Score Total: 100

Similar documents
CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE 344 Midterm Exam

CSE 344 Midterm. Friday, February 8, 2013, 9:30-10:20. Question Points Score Total: 100

CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

CSE 344 Final Examination

CSE 344 Midterm Exam

CSE 344 Midterm Exam Nov. 3, 2014 Sample Solution

CSE 344 Final Examination

CSE 414 Midterm. Friday, April 29, 2016, 1:30-2:20. Question Points Score Total: 100

CSE414 Midterm Exam Spring 2018

CSE344 Midterm Exam Fall 2016

CSE 344 Final Examination

CSE 344 Final Exam. March 17, Question 1 / 10. Question 2 / 30. Question 3 / 18. Question 4 / 24. Question 5 / 21.

CSE 344 Midterm. Wednesday, Oct. 31st, 2018, 1:30-2:20. Question Points Score Total: 100

CSE 344 Midterm. Monday, February 6, 2012, 9:30-10:20. This is a closed book exam. You have 50. Please write your answers in the space provided.

CSE344 Midterm Exam Winter 2017

CSE 344 JANUARY 5 TH INTRO TO THE RELATIONAL DATABASE

CSEP 514 Midterm. Tuesday, Feb. 7, 2017, 5-6:20pm. Question Points Score Total: 150

CSE 344 Midterm. Wednesday, Nov. 1st, 2017, 1:30-2:20. Question Points Score Total: 100

CSE 444 Midterm Test

CSE 344 Final Examination

Midterm Exam #2 (Version B) CS 122A Spring 2018

Midterm Exam #2 (Version A) CS 122A Winter 2017

CSE 414 Midterm. April 28, Name: Question Points Score Total 101. Do not open the test until instructed to do so.

CSE 414 Final Examination

Midterm Exam #2 (Version B) CS 122A Spring 2018

Introduction to Data Management CSE 344. Lecture 14: Relational Calculus

CS 474, Spring 2016 Midterm Exam #2

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Database Systems: Fall 2015 Quiz I

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

CSE344 Final Exam Winter 2017

Computer Science 597A Fall 2008 First Take-home Exam Out: 4:20PM Monday November 10, 2008 Due: 3:00PM SHARP Wednesday, November 12, 2008

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Rela+onal Algebra. Rela+onal Query Languages. CISC437/637, Lecture #6 Ben Cartere?e

IMPORTANT: Circle the last two letters of your class account:

Math 355: Linear Algebra: Midterm 1 Colin Carroll June 25, 2011

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Database Systems: Fall 2009 Quiz I Solutions

Chapter 2: Intro to Relational Model

2.3 Algorithms Using Map-Reduce

Midterm Exam. Name: CSE232A, Winter February 21, Brief Directions:

CS 411a/433a/538a Databases II Midterm, Oct. 18, Minutes. Answer all questions on the exam page. No aids; no electronic devices.

Introduction to Database Systems CSE 414

Exam 1 CS x265 Spring 2018 Name: KEY. I will not use notes, other exams, or any source other than my own brain on this exam:

Introduction to Data Management CSE 344. Lecture 2: Data Models

Principles of Database Systems CSE 544. Lecture #2 SQL The Complete Story

Chapter 6 - Part II The Relational Algebra and Calculus

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3

The Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination

CS 2316 Exam 4 Fall 2011

CIS 330: Applied Database Systems

CS 186, Fall 1999 Midterm 2 Professor Hawthorn

Multisets and Duplicates. SQL: Duplicate Semantics and NULL Values. How does this impact Queries?

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

What is an algebra? A formal system of manipulation of symbols to deal with general statements of relations.

Relational Algebra and SQL

Chapter 2: Intro to Relational Model

Introduction to Database Systems CSE 414

Lecture 2: Introduction to SQL

CSE 344 APRIL 16 TH SEMI-STRUCTURED DATA

University of California, Berkeley. (2 points for each row; 1 point given if part of the change in the row was correct)

Introduction to Databases CSE 414. Lecture 2: Data Models

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20

Announcements. Two typical kinds of queries. Choosing Index is Not Enough. Cost Parameters. Cost of Reading Data From Disk

Announcements. Outline UNIQUE. (Inner) joins. (Inner) Joins. Database Systems CSE 414. WQ1 is posted to gradebook double check scores

SQL Part 3: Where Subqueries and other Syntactic Sugar Part 4: Unknown Values and NULLs

CS 186, Fall 1999 Midterm 2 Professor Hawthorn

Announcements. Using Electronics in Class. Review. Staff Instructor: Alvin Cheung Office hour on Wednesdays, 1-2pm. Class Overview

Database Theory VU , SS Introduction: Relational Query Languages. Reinhard Pichler

Midterm Examination CS 265 Spring 2015 Name: I will not use notes, other exams, or any source other than my own brain on this exam: (please sign)

CSE 344 MAY 7 TH EXAM REVIEW

Midterm Review. Winter Lecture 13

Announcements. JSon Data Structures. JSon Syntax. JSon Semantics: a Tree! JSon Primitive Datatypes. Introduction to Database Systems CSE 414

MapReduce Patterns. MCSN - N. Tonellotto - Distributed Enabling Platforms

Midterm Exam #2 (Version C) CS 122A Spring 2018

Relational Databases

CSE 344 Final Review. August 16 th

Introduction to Data Management CSE 344. Lecture 12: Relational Calculus

Database Systems CSE 414

CPS 216 Spring 2003 Homework #1 Assigned: Wednesday, January 22 Due: Monday, February 10

4. SQL - the Relational Database Language Standard 4.3 Data Manipulation Language (DML)

CSE 344 Final Examination

Fall, 2004 CIS 550. Database and Information Systems Midterm Solutions

JSON - Overview JSon Terminology

SELECT Product.name, Purchase.store FROM Product JOIN Purchase ON Product.name = Purchase.prodName

CSCI 5333 DBMS Fall 2018 Mid-Term Examination. Last Name: First Name: Student Id:

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

CSE-6490B Final Exam

Relational Model, Relational Algebra, and SQL

CS157a Fall 2018 Sec3 Home Page/Syllabus

NULL. The special value NULL could mean: Unknown Unavailable Not Applicable

Practice Final. Read all the problems first before start working on any of them, so you can manage your time wisely

Relational Algebra and SQL

Database Usage (and Construction)

Do we really understand SQL?

10/18/2017. Announcements. NoSQL Motivation. NoSQL. Serverless Architecture. What is the Problem? Database Systems CSE 414

Transcription:

CSE 344 Midterm Monday, Nov 4, 2013, 9:30-10:20 Name: Question Points Score 1 30 2 10 3 50 4 10 Total: 100 This exam is open book and open notes but NO laptops or other portable devices. You have 50 minutes; budget time carefully. Please read all questions carefully before answering them. Some questions are easier, others harder. Plan to answer all questions, do not get stuck on one question. If you have no idea how to answer a question, write your thoughts about the question for partial credit. Good luck! 1

1 SQL 1. (30 points) A sparse matrix is a matrix A = (a ij ) where many elements a ij are 0. A sparse matrix can be stored in a relation with three attributes: A(i, j, v) where i, j are the row and column and v the value of the element in that row and column. For example the matrix: can be represented as: A = 30 0 0 10 0 0 0 10 50 i j v 1 1 30 2 1-10 3 2 10 3 3 50 Notice that it s OK to keep 0 values, even though it may be less efficient. For example, the matrix above can also be represented as: i j v 1 1 30 1 2 0 1 3 0 2 1-10 3 2 10 3 3 50 Page 2

Reference for SQL Syntax Outer Joins -- left outer join with two selections: select * from R left outer join S on R.x=55 and R.y=S.z and S.u=99 The UNION Operation: select R.k from R union select S.k from S The CASE Statement: select R.name, (case when R.rating=1 then like it when R.rating=0 then do not like it when R.rating is null then do not know else unknown end) as my_rating from R; The WITH Statement Note: with is not supported in sqlite, but it is supported SQL Server and in postgres. with T as (select * from R where R.K>10) select * from T where T.K<20 Reference for the Relational Algebra Page 3

(a) (15 points) You are given two sparse matrices A, B with schemas: A(i,j,v) B(j,k,v) Write an SQL query that computes the product matrix A B. Your query should return a set of triples (i, k, v) representing the product matrix; you do not need to remove the entries with value 0. Recall that the product of an m n matrix A = (a ij ) with an n p matrix B = (b jk ) is the m p matrix C = (c ik ) where c ik = j=1,n a ijb jk. For example: Turn in a SQL query: 30 0 0 10 0 0 0 10 50 0 0 0 0 2 4 0 0 1 = 0 0 0 0 0 0 0 20 10 Page 4

(b) (15 points) You are given two sparse matrices A, B with schemas: A(i,j,v) B(i,j,v) Write an SQL query that, given two sparse matrices A, B computes the sum matrix A+B. Your query should return a set of triples (i, j, v) representing the sum matrix; you do not need to remove the entries with value 0. For example: 30 0 0 10 0 0 0 10 50 Turn in a SQL query: + 0 0 0 0 2 4 0 0 1 = 30 0 0 10 2 4 0 10 49 Page 5

2 Indexes and Query Evaluation 2. (10 points) Consider the following two relations: Person(pid, name) Order(oid, pid, product, quantity, date) We create the following indexes: create index Person_pid on Person(pid) create index Person_name on Person(name) create index Order_oid on Order(oid) create index Order_pid on Order(pid) create index Order_product on Order(product) Consider the following two SQL queries: -- Q1 select product, quantity, date from Person, Order where Person.name = Alice and Person.pid = Order.pid -- Q2 select name from Person, Order where Person.pid = Order.pid and Order.product = Tablet (a) (5 points) Which indexes may be useful for query Q1? Person pid Person name Order oid Order pid Order product Answer Y/N: (b) (5 points) Which indexes may be useful for query Q2? Person pid Person name Order oid Order pid Order product Answer Y/N: Page 6

3 Datalog, Relational Calculus, Relational Algebra 3. (50 points) Consider the following two relations: Person(id, name) Trusts(id1, id2) (a) (10 points) Write a program in non-recursive datalog-with-negation that returns the id s and names of all persons who don t trust Alice. Turn in a datalog program: (b) (10 points) Write a program in non-recursive datalog-with-negation that returns the id s and names of all persons who trust only Alice. (In particular, your query should return all persons who don t trust anyone, e.g. persons who do not appear in Trust.) Turn in a datalog program: Page 7

(c) (20 points) Consider the following query in the relational calculus: A(x, n) =Person(x, n) y.(trusts(x, y) z.(trusts(y, z) Person(z, Alice ))) i. Write this query in non-recursive datalog-with-negation. Turn in a datalog program: ii. Write this query in SQL. Turn in a SQL query: Page 8

(d) (10 points) Consider the following SQL query: select distinct t1.id1 from Trusts t1, Person p1 where t1.id2 = p1.id and p1.name = Alice and not exists (select * from Trusts t2, Person p2 where p1.id = t2.id1 and t2.id2 = p2.id and p2.name = Bob ) Write this query in the Relational Algebra. Turn in a Relational Algebra plan: Page 9

4 XML and XPath 4. (10 points) For each statement below indicate whether it is true or false. (a) (1 point) XML is better suited than the relational data model for data exchange between applications. (b) (1 point) The data model for XML is a tree. (c) (1 point) B + trees are stored in XML (d) (1 point) An XML tree can be at most 6 levels deep. (e) (1 point) The tuples in a relation are unordered. (f) (1 point) The elements in an XML document are unordered (a) (b) (c) (d) (e) (g) (1 point) The Data Independence principle states that the tuples in a relation must be independent of each other. (h) (1 point) The Data Independence principle states that applications should be written independently of the way the data is stored and organized. (i) (1 point) All elements returned by the XPath expression /a//b[c=4]/d are of type <d>...</d>. (j) (1 point) If the XPath expression /a//b[c=4] returns 10 elements, then the XPath expression /a//b/c must return at least 10 elements. (f) (g) (h) (i) (j) Page 10