25
Analysis of Midterm-Examination Oct. 22, 2014 ACS-7102 Yangjun Chen 1 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.

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

Embed Size (px)

Citation preview

Page 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 1

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.

Page 2: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 2

faculty

professor

course

student

ER-model:

belong

head

provide

choose

teach

F-name F-Id NoProf

birthdatename sex major

name

couresId

name ID addr.

startdate

1

1

1

N

NM

N

1M

N

take

SIN

sex

salary

section-IDs

M

N

mandatory-optional

ID

SIN

addr.

creditHours

Page 3: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 3

2. (a) Give the algorithm to store a B+-tree (a linked list stored in mainmemory) in a data file. (10)(b) Apply the algorithm to the tree shown in Fig. 1 and give theresult (i.e., the data file storing the tree). (10)

61

5 10

113 9 13

13 6 9 3 1 11

0 1 2

Page 4: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 4ACS-7102 Yangjun Chen 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 x1, …, xk be the children of v;for (i = k to 1) {push(xi, ad, i)};

}

data address-of-parent

position

stack: S

Store a B+-tree on hard disk

Page 5: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 5

1 5 2 100

1

2

3

B+-tree stored in a file:

1 2 3 1

6 0 9 1

11 2 13 0

3

61

5 10

113 9 13

13 6 9 3 1 11

0 1 2

data add.-of-p position

5, 10 -1 -1

5 100

Page 6: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 6

data add.-of-p position

11, 13 0 3

5 100

6, 9 0 2

1, 3 0 1

data add.-of-p position

11, 13 0 36, 9 0 2

1 5 100

1 1 2 3 1

Page 7: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 7

data add.-of-p position

11, 13 0 3

1 5 2 100

1

2

1 2 3 1

6 0 9 1

data add.-of-p position

1 5 2 100

1

2

3

1 2 3 1

6 0 9 1

11 2 13 0

3

Page 8: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 8

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 projectscontrolled 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

Page 9: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 9

DEPT_P PNUMBER(DNDN.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))

Page 10: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 10

4. (20) Construct an R-tree over a set of records for geographicalobjects 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 andat least two pointers; and each internal node at most 2pointers and at least 1 pointer.Please give the computation process.

Page 11: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 11

((0, 40), (60, 50))

road1

((0, 0), (60, 50))

road1 road2

((0, 0), (60, 50))

Road1 road2 house1

((0, 0), (80, 50))

Road1 road2 house1 house2

[(0, 40), (60, 50)] ---- road1 [(40, 0), (60, 40)] ---- road2

[(15, 25), (35, 35)] ---- house1 [(70, 40), (80, 50)] ---- house2

Page 12: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 12

((0, 0), (60, 50)) ((70, 5), (80, 50))

house2 house3road1 road2 house1

• 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 squareunits.

((0, 0), (80, 50)) ((70, 5), (80, 50))

house2 house3road1 road2 house1 pipeline

[(70, 5), (80, 15)] ---- house3

[(35, 25), (80, 35)] ---- pipeline

Page 13: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 13

[(0, 0), (60, 50)] [(70, 5), (80, 50)]

[(0, 0), (80, 50)] [(35, 5), (80, 50)]

[(35, 25), (80, 35)] ---- pipeline

Page 14: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 14

5. (15) Please give the algorithm for transforming any XML documentto a tree structure. Apply the algorithm to the following documentand trace the computation process.<book>

<title>“The Art of Programming”

</title><author>

“D. Knuth”</author><year>

“1969”</year>

</book>

<book>

<title> <author> <year>

“The Art ofProgramming”

“D. Knuth” “1969”

Page 15: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 15

node_value Point_to_node

stack S:

Read a file into a character array A:

< b o o k > < t i t l e > “ T h e A r t …

Transform an XML document to a tree

Page 16: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 16

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

Page 17: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 17

<book>

<book><title>

“The Art of Programming”</title><author>

“D. Knuth”</author><year>

“1969”</year>

</book> <book>

<title>

<book>

<title>

The Art ofProgramming

<book>

The Art ofProgramming

<book>

<title>

<book>

Page 18: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 18

<book><title>

“The Art of Programming”</title><author>

“D. Knuth”</author><year>

“1969”</year>

</book>

<book>

<author>

The Art ofProgramming

<book>

The Art ofProgramming D. Knuth

<book>

<year>

The Art ofProgramming

D. Knuth

Page 19: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 19

<book><title>

“The Art of Programming”</title><author>

“D. Knuth”</author><year>

“1969”</year>

</book>

<book>

<year>

The Art ofProgramming

D. Knuth 1969

<book> The Art ofProgramming

D. Knuth 1969The Art ofProgramming

D. Knuth 1969

empty

book

yearauthortitle

Page 20: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 20

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:

Page 21: 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

Analysis of Midterm-Examination

<? Xml version = “1.0” encoding = “utf-8” standalone = “yes” ?>< md : StarMoviedata xmlns : md = http://infolab.stanford.edu/movies >

<Star starID = “cf” starredIn = “sw”><Name>Carrie Fishes</Name><Address>

<Street>123 Maple St.</Street><City>Hollywood</City></Address><Address>

<Street>5 Locust Ln.</Street><City>Malibu</City><Address>

</Star><Star starID = “mh” starredIn = “sw”>

<Name>Mark Hamill</Name><Street>456 Oak Rd.</Street>

<City>Brentwood</City></Star><Movie movieID = “sw” starsOf = “cf mh”>

<Title>Star Wars</title><Year>1977</Year></Movie>

</StarMovieData>Oct. 22, 2014 ACS-7102 Yangjun Chen 21

12

345

67 8 9

1011

12 13 14

1516

17 18 1920

2122

23

24 25 26

Page 22: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 22

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]

Page 23: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 23

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]

Page 24: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 24

 7. (5) Please give the compressed bit string of the following bit map: 

000000010001

r’ = b2(i)b1(i). r1 = 00000001

b11 = 7 = 111, b12 = 110

r2 = 0001

b11 = 3 = 11, b12 = 10

r1’ = 110111

r2’ = 1011

000000010001 r1’ r2’ = 1101111011

Page 25: 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

Analysis of Midterm-Examination

Oct. 22, 2014 ACS-7102 Yangjun Chen 25

<? Xml version = “1.0” encoding = “utf-8” standalone = “yes” ?>< md : StarMoviedata xmlns : md = http://infolab.stanford.edu/movies >

<Star starID = “cf” starredIn = “sw”><Name>Carrie Fishes</Name><Address>

<Street>123 Maple St.</Street><City>Hollywood</City></Address><Address>

<Street>5 Locust Ln.</Street><City>Malibu</City><Address>

</Star><Star starID = “mh” starredIn = “sw”>

<Name>Mark Hamill</Name><Street>456 Oak Rd.</Street><City>Brentwood</City>

</Star><Movie movieID = “sw” starsOf = “cf”, “mh”>

<Title>Star Wars</title><Year>1977</Year></Movie>

</StarMovieData>