Presentation is loading. Please wait.

Presentation is loading. Please wait.

Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen1 1.(15) Draw an ER-diagram to describe the following real world problem. (a)A university.

Similar presentations


Presentation on theme: "Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen1 1.(15) Draw an ER-diagram to describe the following real world problem. (a)A university."— Presentation transcript:

1 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen1 1.(15) Draw an ER-diagram to describe the following real world problem. (a)A university is organized into faculties. (b)Each faculty has a unique name, ID and number of professors and a specific professor is chosen as the faculty head. (c)Each faculty provides a number of courses. (d)Each course has a unique name and courseID. (e)Each professor has a name, SIN, address, salary, sex and courses taught by him/her. (f)Each professor belongs to a faculty and can teach several sections of a course. (g)Each student has a name, ID, SIN, address, GPA, sex, and major. (h)Each student can choose one faculty as his/her major faculty and take several courses with certain credit hours. Some of the courses are mandatory and some are optional.

2 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen2 faculty professor course student ER-model: belong head provide choose teach F-name F-Id NoProf birthdatenamesex major name couresId name IDaddr. startdate 1 1 1 N N M N 1 M N take SIN sex salary section-IDs M N mandatory-optional ID SIN addr. creditHours

3 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen3 2. (a) Give the algorithm to store a B+-tree (a linked list stored in main memory) in a data file. (10) (b) Apply the algorithm to the tree shown in Fig. 1 and give the result (i.e., the data file storing the tree). (10) 61 5 10 11 3 913 13693111 012

4 Analysis of Midterm-Examination Oct. 22, 2014 ACS-7102 Yangjun Chen4 4 Algorithm: push(root, -1, -1); while (S is not empty) do {x := pop( ); store x.data in file F; assume that the address of x in F is ad; if x.address-of-parent  -1 then { y := x.address-of-parent; z := x.position; write ad in page y at position z in F; } let x 1, …, x k be the children of v; for (i = k to 1) {push(x i, ad, i)}; } dataaddress-of- parent position stack: S Store a B+-tree on hard disk

5 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen5 15215210 01230123 B+-tree stored in a file: 1231231 6096091 112130 3 61 5 10 11 3 913 13693111 012 dataadd.-of-pposition 5, 10 510 0

6 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen6 dataadd.-of-pposition 11, 1303 510 0 6, 902 1, 301 dataadd.-of-pposition 11, 1303 6, 902 151510 0101 1231231

7 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen7 dataadd.-of-pposition 11, 1303 15215210 012012 1231231 6096091 dataadd.-of-pposition 15215210 01230123 1231231 6096091 112130 3

8 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen8 3.(10) Given the relation schemas shown in Fig. 2, construct expressions (using relational algebraic operations) to evaluate the following query: Find the names of employees who works on all the projects controlled by department ‘Applied Computer Science’. fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno Dname, dnumber, mgrssn, mgrstartdate EMPLOYEE DEPARTMENT Pname, pnumber, plocation, dnum PROJECT Essn pno, hours WORKS_ON Fig. 2

9 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen9 DEPT_P   PNUMBER (DN DN.dnumber = PROJECT.dnumber (PROJECT)) EMP_PNOS   ESSN,PNO (WORK_ON) SSNS  EMP_PNOS : DEPT_P RESULT   FNAME, LNAME (SSNS * EMPLOYEE) DN   dnumber (  Dname = ‘Applied Computer Science’ (Department))

10 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen10 4. (20) Construct an R-tree over a set of records for geographical objects with the following coordinates [(x1, y1), (x2, y2)]: [(0, 40), (60, 50)] ---- road1 [(40, 0), (60, 40)] ---- road2 [(15, 25), (35, 35)] ---- house1 [(70, 40), (80, 50)] ---- house2 [(70, 5), (80, 15)] ---- house3 [(35, 25), (80, 35)] ---- pipeline Assume that each leaf node can have at most 4 pointers and at least two pointers; and each internal node at most 2 pointers and at least 1 pointer. Please give the computation process.

11 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen11 ((0, 40), (60, 50)) road1 ((0, 0), (60, 50)) road1road2 ((0, 0), (60, 50)) Road1road2house1 ((0, 0), (80, 50)) Road1road2house1house2 [(0, 40), (60, 50)] ---- road1[(40, 0), (60, 40)] ---- road2 [(15, 25), (35, 35)] ---- house1 [(70, 40), (80, 50)] ---- house2

12 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen12 ((0, 0), (60, 50))((70, 5), (80, 50)) house2house3road1road2house1 If we expand the first subregion in the internal node, then we add 1000 square units to the region. If we extend the other subregion in the internal, then we add 1575 square units. ((0, 0), (80, 50))((70, 5), (80, 50)) house2house3road1road2house1pipeline [(70, 5), (80, 15)] ---- house3 [(35, 25), (80, 35)] ---- pipeline

13 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen13 [(0, 0), (60, 50)] [(70, 5), (80, 50)] [(0, 0), (80, 50)] [(35, 5), (80, 50)] [(35, 25), (80, 35)] ---- pipeline

14 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen14 5. (15) Please give the algorithm for transforming any XML document to a tree structure. Apply the algorithm to the following document and trace the computation process. “The Art of Programming” “D. Knuth” “1969” “The Art of Programming” “D. Knuth”“1969”

15 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen15 node_value Point_to_node stack S: Read a file into a character array A : “ T h e A r t … Transform an XML document to a tree

16 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen16 Algorithm: Scan array A; If A[i] is ‘<’ and A[i+1] is a character then { generate a node x for A[i..j], where A[j] is ‘>’ directly after A[i]; let y = S.top().pointer_to_node; make x be a child of y; S.push(A[i..j], x); If A[i] is ‘ ‘‘ ’, then { genearte a node x for A[i..j], where A[j] is ‘ ’’ ’ directly after A[i]; let y = S.top().pointer_to_node; make x be a child of y; If A[i] is ‘<’ and A[i+1] is ‘/’, then S.pop(); Transform an XML document to a tree

17 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen17 “The Art of Programming” “D. Knuth” “1969” The Art of Programming The Art of Programming

18 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen18 “The Art of Programming” “D. Knuth” “1969” The Art of Programming The Art of Programming D. Knuth The Art of Programming D. Knuth

19 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen19 “The Art of Programming” “D. Knuth” “1969” The Art of Programming D. Knuth 1969 The Art of Programming D. Knuth 1969 The Art of Programming D. Knuth 1969 empty book year author title

20 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen20 6. (15) In order to represent XML documents as relations, we should give each document and each element of a document a unique ID. For each document, the ID could be its URL or path in a file system. A possible relational database schema: DocRoot(docID, rootElmentID) ElementValue(elementID, value) SubElement(parentID, childID, position) ElementAttribute(elementID, name, value) Please show the tables after we have put the following document into the tables :

21 Analysis of Midterm-Examination Carrie Fishes 123 Maple St. Hollywood 5 Locust Ln. Malibu Mark Hamill 456 Oak Rd. Brentwood Star Wars 1977 Oct. 22, 2014ACS-7102 Yangjun Chen21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

22 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen22 DocRoot(docID, rootElmentID) [1, 1] ElementValue(elementID, value) [1, md: StarMoviedata] [2, Star] [3, Name] [4, “Carrie Fishes”] [5, Address] [6, Street] [7, “123 Maple St.”] [8, City] [9, Hollywood] [10, address] [11, Street] [12, 5 Locus Ln.] [13, City] [14, Malibu] [15, Star] [16, name] [17, Mark Hamill] [18, Street] [19, 456 Oak Rd.] [20, City] [21, Brentwood] [22, Movie] [23, Title] [24, Star wars] [25, Year] [26, 1977]

23 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen23 SubElement(parentID, childID, position) [1, 2, 1] [1, 15, 2] [1, 22, 3] [2, 3, 1] [2, 5, 2] [2, 10, 3] [3, 4, 1] [5, 6, 1] [5, 8, 2] ElementAttribute(elementID, name, value) [1, xnmns: md, http:// …] [2, starID, “cf”] [2, starredIn, “sw”] [15, starID, “mh”] [15, starredIn, “sw”] [22, movieID, “sw”] [22, starsOf, “cf mh”] [6, 7, 1] [8, 9, 1] [10, 11, 1] [10, 13, 2] [11, 12, 1] [13, 14, 1] [15, 16, 1] [15, 18, 2] [15, 20, 3] [16, 17, 1] [18, 19, 1] [20, 21, 1] [22, 23, 1] [22, 25, 2] [23, 24, 1] [25, 26, 1]

24 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen24 7. (5) Please give the compressed bit string of the following bit map: 000000010001 r’ = b 2 (i)b 1 (i). r 1 = 00000001 b 11 = 7 = 111, b 12 = 110 r 2 = 0001 b 11 = 3 = 11, b 12 = 10 r 1 ’ = 110111 r 2 ’ = 1011 000000010001 r 1 ’ r 2 ’ = 1101111011

25 Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen25 Carrie Fishes 123 Maple St. Hollywood 5 Locust Ln. Malibu Mark Hamill 456 Oak Rd. Brentwood Star Wars 1977


Download ppt "Analysis of Midterm-Examination Oct. 22, 2014ACS-7102 Yangjun Chen1 1.(15) Draw an ER-diagram to describe the following real world problem. (a)A university."

Similar presentations


Ads by Google