1 / 13

Assignment #2 Due: Feb. 22, 2010

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;

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 3, 5 -1 -1 B+-tree file 0 3 5 1, 3 0 1 S: B+-tree file 4 0 2 0 13 5 6 0 3 1 1 3 4 0 2 6 0 3 S: S: data address-of- parent position key values ACS-7102 Yangjun Chen

  3. S: B+-tree file 0 132 5 1 1 3 2 4 6 0 3 S: data address-of- parent position key values S: B+-tree file 0 132 5 3 1 1 3 empty 2 4 3 6 ACS-7102 Yangjun Chen

  4. / a / b [ / / c “ M a l i b “ a n d … • 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: When we scan A, we will meet the following different cases: ‘/’ followed by a character, ‘//’, ‘[’ Comparison symbols: ‘=’, ‘<’, ‘>’, ‘<>’, ‘≠’ 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 node P 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 ofr. r := p. If A[i..i+1] = ‘//’, create a node P 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 ofr. r := p. ACS-7102 Yangjun Chen

  6. If A[i] is a comparison symbol, create a node p for the value. Make p a child of r. Label the edge with the symbol. If A[i] = ‘[’, recognize the conditions C between the ‘[‘ and the matching ‘]’ following A[i]. Assume that it is 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 Tabe the subtree created by the recursive call; make it a subtree of r; } i := j + 1. If i = n + 1, remove the virtual node and return the tree. ACS-7102 Yangjun Chen

  7. root book author author writing writing cf mh sw authorOf authorOf city address name name publisher address street year title ad1 ad2 Mark Hamill Carrie Fisher Oak B’wood Star War The MIT Press 1977 city street city street Maple H’wood Locust Malibu • 3. (a) Represent the following graph as an XML document. 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> 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 Author AuthorId ID #REQUIRED writing INREFS #IMPLIED > <!ELEMENT Name (#PCDATA)> <!ELEMENT Address (Street, City)> <!ELEMNT Street (#PCDATA)> <!ELEMENT City (#PCDATA)> <!ELEMENT Book (Title, Publisher, Year)> <!ATTLIST Book BookIn ID #REQUIRED authorOf IDREFS #REQUIRED > <!ELEMENT Title (#PCDATA)> <!ELEMENT Publisher (#PCDATA)> <!ELEMENT Year (#PCDATA)> ]> 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> 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> 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> 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> ACS-7102 Yangjun Chen

More Related