assignment #2 due: feb. 22, 2010

13
Analysis of Midterm-Examination Jan. 2012 ACS-7102 Yangjun Chen 1 Assignment #2 Due: Feb. 22, 2010 1.Apply the following algorithm to the B+-tree shown in Fig. 4 to store it in a data file. Trace the computation process. 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)}; } 6 4 1 3 5 3 5 Fig. 4

Upload: theodora-xena

Post on 30-Dec-2015

32 views

Category:

Documents


0 download

DESCRIPTION

3. 5. 5. 4. 6. 1. 3. Assignment #2 Due: Feb. 22, 2010 Apply the following algorithm to the B+-tree shown in Fig. 4 to store it in a data file. Trace the computation process. Algorithm:. push(root, -1, -1); while (S is not empty) do {x := pop( ); store x.data in file F; - PowerPoint PPT Presentation Copyright Complaint Adult Content Flag as Inappropriate Report This Download Presentation Assignment #2 Due: Feb. 22, 2010 An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - Presentation Transcript 3 5 5 4 6 1 3 Assignment #2 Due: Feb. 22, 2010 Apply the following algorithm to the B+-tree shown in Fig. 4 to store it in a data file. Trace the computation process. 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)}; } Fig. 4 ACS-7102 Yangjun Chen

TRANSCRIPT

Page 1: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 1

Assignment #2

Due: Feb. 22, 2010

1. Apply the following algorithm to the B+-tree shown in Fig. 4 to store it in a data file. Trace the computation process.

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)};

}

641 3

53 5

Fig. 4

Page 2: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 2

data address-of-parent

position

key values

S:

3, 5 -1 -1

3 50

B+-tree file

6 0 3

4 0 2

1, 3 0 1

S:

1 3 50

B+-tree file

6 0 3

4 0 2

S:

1 1 3

Page 3: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 3

data address-of-parent

position

key values

S:

1 3 2 50

B+-tree file

6 0 3

S:

1 1 3

4 2

1 3 2 50

B+-tree file S:

1 1 3

4 2

6 3

3

empty

Page 4: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 4

2. Write an algorithm to transform a simplified XPath expression (in which the subexpressions in any condition can be connected only with , e.g., /StarMovieData/Star[//City = “Malibu” and //Street = “123 Maple St.”]/Name) to a tree structure.

/StarMovieData/Star[//City = “Malibu”]/Name

/a/b[//c = “Malibu” and //d = 5]/e

Assume that an XPath is stored in a character array A:

/ a / b [ / / c “ M a l i b “ a n d …

When we scan A, we will meet the following different cases:‘/’ followed by a character,‘//’,‘[’Comparison symbols: ‘=’, ‘<’, ‘>’, ‘<>’, ‘≠’

Page 5: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 5

Before we scan A, a virtual root r is created.

Algorithm tree-generation(A):

Scan array A;If A[i] is ‘/’ followed by a character, create a nodeP labeled with the string A[i+1..j] such that A[j+1]is ‘/’,‘[‘, or a comparison symbol. i := j + 1.Make p a /-child of r. r := p.

If A[i..i+1] = ‘//’, create a nodeP labeled with the string A[i+2..j] such that A[j+1]is ‘/’,‘[‘, or a comparison symbol. i := j + 1.Make p a //-child of r. r := p.

Page 6: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 6

If A[i] is a comparison symbol, create a node p forthe value. Make p a child of r. Label the edge withthe symbol.

If A[i] = ‘[’, recognize the conditions C between the‘[‘ and the matching ‘]’ following A[i]. Assume that itis A[j]. Let C = path1 and path2 and … and pathk.Do the following:

for a = 1 to k do{ call tree-generation(patha);

assume that Ta be the subtree created by therecursive call; make it a subtree of r;

} i := j + 1.

If i = n + 1, remove the virtual node and return thetree.

Page 7: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 7

3. (a) Represent the following graph as an XML document.

sw

book

title year

CarrieFisher street city street city

Maple H’wood Locust Malibu

MarkHamill Oak B’wood 1977

cf mh

root

author

name nameaddress

addressstreet

city

writing

authorOf

writingauthorOf

StarWar

ad1 ad2

author

The MITPress

publisher

Page 8: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 8

<? Xml version = “1.0” encoding = “utf-8” standalone = “yes” ?><StarMovieData>

<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” starOf = “cf mh”>

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

</StarMovieData>

Page 9: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 9

(b) The following is a DTD for books. Please produce an XML document conforming to the DTD.

<!DOCTYPE AuthorBook [<!ELEMENT AuthorBook (Author*, Book*)><!ELEMENT Author (Name, Address+)>

<!ATTLIST AuthorAuthorId ID #REQUIREDwriting INREFS #IMPLIED

><!ELEMENT Name (#PCDATA)><!ELEMENT Address (Street, City)><!ELEMNT Street (#PCDATA)><!ELEMENT City (#PCDATA)><!ELEMENT Book (Title, Publisher, Year)>

<!ATTLIST BookBookIn ID #REQUIREDauthorOf IDREFS #REQUIRED

><!ELEMENT Title (#PCDATA)> <!ELEMENT Publisher (#PCDATA)><!ELEMENT Year (#PCDATA)>

]>

Page 10: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 10

4. Define an XML-schema which is equivalent to the DTD shown in Question 3(b).

<? Xml version = “1.0” encoding = “utf-8” ?><xs: schema xmlns: xs = “http://www.w3.org/2001/XMLSchema”>

<xs:complexType name = “authorType”><xs: sequence>

<xs: attribute name = “AuthorID” type = “xs: string” /></xs: attribute name = “Writing” type = “xs: string” />

</xs: sequence></xs: complexType>

<xs:complexType name = “bookType”><xs: sequence>

<xs: attribute name = “BookID” type = “xs: string” /></xs: attribute name = “authorOf” type = “xs: string” />

</xs: sequence></xs: complexType>

Page 11: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 11

<xs:complexType name = “addressType”><xs: sequence>

<xs: element name = “street” type = “xs: string” /></xs: element name = “city” type = “xs: string” />

</xs: sequence></xs: complexType>

Page 12: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 12

<xs: element name = “AuthorBook”><xs: complexTyp>

<xs: sequence><xs: element name = “Author” type = “authorType”

minOccurs = “0” maxOcurs = “unbouned” /><xs: complexType>

<xs: sequence><xs: element name = “name” type = “xs: string” /></xs: element name = “Address” type = “addressType”minOccurs = “1” maxOcurs = “unbouned” />

</xs:sequence></xs: complexType>

</xs:element>

Page 13: Assignment #2 Due: Feb. 22, 2010

Analysis of Midterm-Examination

Jan. 2012 ACS-7102 Yangjun Chen 13

<xs: element name = “Book” type = “bookType”minOccurs = “0” maxOcurs = “unbouned” /><xs: complexType>

<xs: sequence><xs: element name = “title” type = “xs: string” /><xs: element name = “Publisher” type = “xs: string” /><xs: element name = “year” type = “xs: string” />

</xs:sequence></xs: complexType>

</xs:element></xs: sequence>

</xs: complexTyp></xs: element>

</xs: schema>