XML and Databases. Exam Preperation Discuss Answers to last year s exam. Sebastian Maneth NICTA and UNSW

Similar documents
Lecture 3. XML Into RDBMS. XML and Databases. Memory Representations. Memory Representations. Traversals and Pre/Post-Encoding. Memory Representations

XML and Databases. Outline. 1. Top-Down Evaluation of Simple Paths. 1. Top-Down Evaluation of Simple Paths. 1. Top-Down Evaluation of Simple Paths

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

CS 360 Exam 2 Fall 2014 Name

Lecture 6: Coding theory

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

CS241 Week 6 Tutorial Solutions

18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

6. Suppose lim = constant> 0. Which of the following does not hold?

Lecture 11 Binary Decision Diagrams (BDDs)

First Midterm Examination

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

NON-DETERMINISTIC FSA

Minimal DFA. minimal DFA for L starting from any other

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Instructions. An 8.5 x 11 Cheat Sheet may also be used as an aid for this test. MUST be original handwriting.

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Finite State Automata and Determinisation

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Now we must transform the original model so we can use the new parameters. = S max. Recruits

Data Structures LECTURE 10. Huffman coding. Example. Coding: problem definition

Factorising FACTORISING.

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Let's start with an example:

CS 275 Automata and Formal Language Theory

CARLETON UNIVERSITY. 1.0 Problems and Most Solutions, Sect B, 2005

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Nondeterministic Finite Automata

Necessary and sucient conditions for some two. Abstract. Further we show that the necessary conditions for the existence of an OD(44 s 1 s 2 )

2.4 Theoretical Foundations

Parse trees, ambiguity, and Chomsky normal form

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

Worked out examples Finite Automata

Formal languages, automata, and theory of computation

Regular languages refresher

A Rewrite Approach for Pattern Containment

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Closure Properties of Regular Languages

Regular Languages and Applications

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Nondeterministic Automata vs Deterministic Automata

Prefix-Free Regular-Expression Matching

First Midterm Examination

Aperiodic tilings and substitutions

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Mid-Term Examination - Spring 2014 Mathematical Programming with Applications to Economics Total Score: 45; Time: 3 hours

CS 573 Automata Theory and Formal Languages

XPath Node Selection over Grammar-Compressed Trees

Regular expressions, Finite Automata, transition graphs are all the same!!

Data Structures (INE2011)

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Equivalent fractions have the same value but they have different denominators. This means they have been divided into a different number of parts.

Chapter 4 State-Space Planning

Lexical Analysis Finite Automate

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

CHAPTER 1 Regular Languages. Contents

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

XML and Databases. Outline. Previous Lecture. XML Type Definition Languages. Sebastian Maneth NICTA and UNSW

CS 491G Combinatorial Optimization Lecture Notes

New data structures to reduce data size and search time

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

CMSC 330: Organization of Programming Languages

Probability The Language of Chance P(A) Mathletics Instant Workbooks. Copyright

Homework 3 Solutions

Data Structures and Algorithm. Xiaoqing Zheng

Solutions to Problem Set #1

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Connectivity in Graphs. CS311H: Discrete Mathematics. Graph Theory II. Example. Paths. Connectedness. Example

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Algebra 2 Semester 1 Practice Final

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

I 3 2 = I I 4 = 2A

Solving the Class Diagram Restructuring Transformation Case with FunnyQT

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh

Graph Algorithms. Vertex set = { a,b,c,d } Edge set = { {a,c}, {b,c}, {c,d}, {b,d}} Figure 1: An example for a simple graph

Logic, Set Theory and Computability [M. Coppenbarger]

Automata and Languages

= state, a = reading and q j

Exam 1 Study Guide. Differentiation and Anti-differentiation Rules from Calculus I

Lesson 2.1 Inductive Reasoning

Fast index for approximate string matching

Harvard University Computer Science 121 Midterm October 23, 2012

GNFA GNFA GNFA GNFA GNFA

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Outline Data Structures and Algorithms. Data compression. Data compression. Lossy vs. Lossless. Data Compression

1.4 Nonregular Languages

Transcription:

XML n Dtses Exm Prepertion Disuss Answers to lst yer s exm Sestin Mneth NICTA n UNSW CSE@UNSW -- Semester 1, 2008

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> ) <uthor><title></uthor></title> ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 2

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr (nnot e erive y grmmr!) ) <uthor><title></uthor></title> ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 3

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 4

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> 5

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> Well-formeness onstrint: No Reursion A prse entity MUST NOT ontin reursive referene to itself, either iretly or iniretly. 6

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> g) <><><></></></>&e;</></> [41] Attriute ::= Nme Eq AttVlue [5] Nme ::= (Letter '_' ':') (NmeChr)* [84] Letter ::= [-za-z] 7

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> WFC g) <><><></></></>&e;</></> Well-formeness onstrint: Unique Att Spe An ttriute nme MUST NOT pper more thn one in the sme strt-tg or empty-element tg. 8

(1) For eh of the following, explin why it is not well-forme XML (is WFC or the XML grmmr violte?) ) <uthor></uthor><title></title> XML grmmr ) <uthor><title></uthor></title> WFC ) <info temp= 25C >ontent</info> XML grmmr (shoul e 25 ; -is tully OK..!) ) <!DOCTYPE greeting [ WFC <!ELEMENT greeting (#PCDATA)> <!ENTITY e1 "&e2; e3"> <!ENTITY e2 "&e3;"> <!ENTITY e3 "&e2;"> ]> <greeting> &e1; </greeting> e) < t1= lh t<2= foo > 1 < 5 </> XML grmmr f) < 3= 2= 1= 2= 5 /> WFC g) <><><></></></>&e;</></> WFC Well-formeness onstrint: Entity Delre...the Nme given in the entity referene MUST mth tht in n entity elrtion tht... 9

(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. 10

(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its 11

(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its ) U+00 UTF-8: 00000000 = 8its UTF-16: 00000000 00000000 = 16its 12

(2) Show sequenes of Unioe hrters for whih ) UTF-8 nees more spe thn UTF-16 ) UTF-16 nees more spe thn UTF-8 together with the orresponing UTF oes n their lengths. ) Explin how to inry sort sequene of UTF-8 hrters. Use pseuo oe if pproprite. ) U+FFFF UTF-8: 11101111 10111111 10111111 = 24its UTF-16: 11111111 11111111 = 16its ) U+00 ) UTF-8: 00000000 = 8its UTF-16: 00000000 00000000 = 16its To inry ompre two hrters, simply strt from the highest it! In this wy, for hrters with ifferent lengths in UTF-8, fter 4 its we will e one! - In se UTF-8 lengths re sme norml inry ompre.. 13

(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. 14

(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] 15

(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] ) getanestors(noe n): NoeSet { NoeSet result=null; } if(n.type!=doc){ for(; n=n->prent ; n.type!= DOC ) A(n,result); A(n,result); } return result; 16

(3) Show n element noe with mixe ontent, using the XML Informtion Set. Assume tht for noe M, Type(M) is it s type, i.e., is one of DOC, ELEM, ATTR, or CHAR. Using the Infoset, show pseuo oe tht, given noe N, ) returns ll nestors of the noe ) returns the previous siling of the noe. lolnme(e1) = elem hilren(e1) = [e2,1] lolnme(e2) = elem hilren(e2) = [] prent(e2) = e1 oe(1) = U+00 prent(1) = e1 ttriutes(e1) = [] ttriutes(e2) = [] ) getanestors(noe n): NoeSet { NoeSet result=null; ) getprevsi(noe n): Noe { NoeList l=null; if(n.type!= DOC ) { Noe prent=n->prentnoe(); l=n->hilren; if(l==null) return NULL; s=first(l); if(s==l) return NULL; while(s->next!=n) s=s->next(); } return s; } } if(n.type!=doc){ for(; n=n->prent ; n.type!= DOC ) A(n,result); A(n,result); } return result; 17

(4) Using DOM, give pseuo oe tht etermines the verge epth of the XML tree. The verge epth of </> is 1. 18

(4) Using DOM, give pseuo oe tht etermines the verge epth of the XML tree. The verge epth of </> is 1. int totl=0; int ount=0; ll laverge(root, 1); return totl/ount; voi laverge(noe n, int epth) { NoeList hilren = n->hillist(); if(hilren->isempty()) { totl += epth; ount++; return; } else for eh Noe in hilren laverge(, epth+1); } 19

(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. 20

(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. When omputing the miniml DAG, we nee to etermine whether given sutree hs ourre lrey. If we keep tle of pointers to the sutrees tht hve ourre lrey, then to hek for given sutree whether or not it ours in the tle tkes in the worst se (#of trees in the tle) x (# noes in sutree) whih, in the worst se, is qurti to the size of the input tree! With hshing, we only nee (# trees in the hsh uket) x (# noes in the sutree). Thus, if uket hs only onstnt numer of trees, on verge, then the omplexity goes from qurti to liner! Exmple tree: k Seen:=NULL Seen:=seen + -tree Contins(Seen, -tree )? nees 1 omprison Seen:=Seen + -tree Contins(Seen, -tree )? nees 2 omprisons Seen:=Seen + -tree Contins(Seen, -tree )? nees 3 omprisons Seen:=Seen + -tree Assume hsh( -tree )=1 hsh( -tree )=2 hsh( -tree )=3 hsh( -tree )=4 Then we nee no (tree) omprisons whtsover! 21

(5) Explin in etil, using n exmple, why hshing is useful for fining the miniml DAG of tree. Why re uptes more expensive on DAG thn on tree? Give n exmple tht lerly explins this. DAG 1: 2: [1,1,1] Duplite noe 2 DAG Insert(2, -tree ) DAG 1: 2: 3: [1,2,1] 1: 2: 3: [2] 4: [1,3,1] Inserting single new hil require ing two rows n hnging one existing one. (the shre 2 n hil -sutree of the -noe must e uplite first, efore the -hil n e e. 22

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. 23

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. 2 3 1 4 9 10 5 6 11 14 7 8 12 13 PRE POST lel 1 14 2 2 3 1 4 7 5 3 6 6 7 4 8 5 9 8 10 13 11 11 12 12 13 10 14 12 24

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) int i=1; Noe n=root; repet{ while(firstchil(n)!=null) n=firstchil(n); post(i)=n; i++; while(nextsiling(n)==nil){ n=prent(n); if(n==null) rek; post(i)=n; i++; } n=nextsiling(n); } 25

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. 26

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. ) If there i noe with pre-vlue > pre n with post-vlue=post-1, then tht is the lst hil of (pre, post) 27

(6) Give the PRE/POST tle for the tree <><></></><></><></></></></></><><></></></></> </></> ) Give pseuo oe tht omputes the POST orer of tree in n itertive wy, i.e., without ny reursive lls(!). You n use firstchil(n), nextsiling(n), n prent(n) for noe n. Using the PRE/POST-enoing, explin how to otin ) the nestors of noe ) the lst hil of noe e) the mximl epth of the sutree t noe. ) Given (pre, post) of noe, its nestors re ll noes with pre-vlue < pre n post-vlue > post. ) If there i noe with pre-vlue > pre n with post-vlue=post-1, then tht is the lst hil of (pre, post) e) int mxdepth(int pr){ size(int p): int{ int s=0; for(int pr2=p+1; post(pr2)<post(p); pr2++) s++ return s; } int D=0; int u,l; L=pr+size(pr)-post(pr); for(int pr2=pr+1; post(pr2)<post(pr); pr2++){ u=pr2+size(pr2)-post(pr2)-l; if(u>d) D=u; return D; } 28

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. 29

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi?? 30

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi?? no! Thus, E is not 1-unmiguous. 31

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. Deterministi utomton: 32

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. NOT equivlent to E! The string is mthe y E, ut NOT y E2. E2 is NOT 1-unmiguous: 33

(8) Show the Glushkov utomton for the regulr expression E=( )*. Is this expression 1-unmiguous? Explin! Give eterministi utomton for the sme expression. Is E2=(*( ))* equivlent to E? Is it 1-unmiguous? Show 1-unmiguous expression tht is equivlent to ( )*. The expression *(*)* is equivlent to E 1-unmiguous. 34

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Wth out! This is typo on your Exm printout.. Sorry. 7: 8: 12: 13: 35

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: ) // 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 36

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: ) // ) //[] 3: 5: 6: 11: 14: 7: 8: 12: 13: 37

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: ) // ) //[] 3: 5: 6: 11: 14: ) //[not()] 7: 8: 12: 13: 38

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe (noe no 11) e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 7: 8: 11: 12: 14: 13: ) // ) //[] ) //[not()] ) //[] or //[ n ] 39

(9) For the tree given in 6, write XPth expressions tht ) selet ll noes ) selet ll noes tht hve -hil ) selet ll noes tht hve no -hilren ) selet the right most -noe (noe no 11) e) selet ll noes tht hve -prent <><></></><></><></></></></></><><></></></></> </></> 1: 2: 4: 9: 10: 3: 5: 6: 7: 8: 11: 12: 14: 13: ) // ) //[] ) //[not()] ) //[] or //[ n ] e) //*[prent::] or ///* 40

(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 41

(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: ) 5, 6, 13 2: 4: 9: 10: 3: 5: 6: 11: 14: 7: 8: 12: 13: 42

(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: ) 5, 6, 13 ) 1, 6, 11 3: 5: 6: 11: 14: 7: 8: 12: 13: 43

(10) Below is tree orresponing to the oument in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 7: 8: 12: 13: 44

(10) This tree orresponing to the XML in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 ) 2, 3, 9, 14 7: 8: 12: 13: 45

(10) This tree orresponing to the XML in (6). Show the sequenes of noe numers tht re selete y the following queries. ) //// ) //*[ or ] ) ///nestor::/following:: ) //*[not(.//./nestor::)] e) /////preeing::*// 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: ) 5, 6, 13 ) 1, 6, 11 ) 9, 13, 14 ) 2, 3, 9, 14 7: 8: 12: 13: e) 5, 6 46

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() Å nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: esennt { root } Å l() 47

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14:? Å following l() Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 48

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() {0,1,4,6,10,11} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 49

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: Å following l() {0,1,4,6,10,11} {6} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 50

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: 2: 4: 9: 10: 3: 5: 6: 11: 14: {9,13,14} Å {9,10,..,14} {5,6,9,13,14} following l() {0,1,4,6,10,11} {6} Å {5,6,9,13,14} nestor l() 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: Å {1,2,..,14} esennt { root } {0} l() {2,7,8,10,12} 51

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} 7: 8: 12: 13: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 52

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} Å - 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: om nestor l() esennt l() {2,7,8,10,12} {3,4,11} 53

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} Å - 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: om {5-8,12,13} {1,4,6,10,11} nestor esennt l() l() {2,7,8,10,12} {3,4,11} 54

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} 7: 8: 12: l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } 13: {0-14} om {1,4,6,10,11} Å - nestor {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 55

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} {0-14} 7: 8: 12: 13: om l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } {1,4,6,10,11} Å - nestor {0,2,3,9,14} {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 56

(10) This tree orresponing to the XML in (6). ) ///nestor::/following:: ) //*[not(.//./nestor::)] For query ) show in etil how the Core-XPth evlution lgorithm omputes the nswer to this query. Do the sme for query ). 0:root 1: {1,2,..,14} Å esennt l(*) 2: 4: 9: 10: {1,2,..,14} { root } 3: 5: 6: 11: 14: {0} {0-14} 7: 8: 12: 13: om l() = { 1 } l() = { 2, 7, 8, 10, 12 } l() = { 3, 4, 11 } l() = { 5, 6, 9, 13, 14 } {1,4,6,10,11} Å - nestor {2,3,9,14} {0,2,3,9,14} {1,4-8,10-13} {5-8,12,13} esennt l() l() {2,7,8,10,12} {3,4,11} 57

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] 58

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] q1 = /// q2 = // or q1 = // q2 = //* 59

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] q1 = /// q2 = // Cnonil moel: Reple in q1 // y N+1 mny /z/ 0, here z Do they mth q2? yes!! or q1 = // q2 = //* 60

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 61

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 62

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 63

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 64

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * 65

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cn not e mppe. 66

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cn not e mppe. Note: p is inlue in q!! 67

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] * * * Cse 1: hs -hil Why? Cse 2: hs no -hil Note: p is inlue in q!! 68

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] OK!! p inlue in q, for Cse 1! * * * Cse 1: hs -hil Why? Cse 2: hs no -hil Note: p is inlue in q!! 69

(11) Show n exmple of XPth queries q1,q2 suh tht they re not equivlent, ut q1 is inlue in q2. Show tht q1 is inlue in q2 using one of the methos isusse. Use the homomorphism tehnique to test whether p=[.//[/*//]/[//]/[/]] is inlue in q=[.//[//*//]/*[/]] Also OK!! p inlue in q, for Cse 2! * * * * Cse 2: hs no -hil Why? Note: p is inlue in q!! 70

(12) Construt DTD suh tht 10) is inlue in 10e), n nother DTD suh tht 10e) is inlue in 10). [Very esy!!] 10) //// 10e) /////preeing::*// 71

(12) Construt DTD suh tht 10) is inlue in 10e), n nother DTD suh tht 10e) is inlue in 10). [Very esy!!] 10) //// 10e) /////preeing::*// For the first prt: *Any DTD* so tht -noes o NOT hve -esennts! For the seon prt: Any DTD, so tht ll -noes re -esennts. 72

(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: 73

(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r1.pre FROM o_tl r1 WHERE r1.pre=1 ORDERED BY r1.pr 74

(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND (r2.pre-r2.post+r2.size)=(r1.pre-r1.post+r1.size)+1 AND r2.tg= AND r3.pre>r2.pre AND r3.post<r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)+1 AND r3.tg= AND r4.pre>r3.pre AND r4.post<r3.post AND (r4.pre-r4.post+r4.size)=(r3.pre-r3.post+r3.size)+1 ORDERED BY r4.pre Rell: level(n) = pre(n) post(n)+size(n) 75

(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND r2.tg= AND r3.pre>r2.pre AND r3.post<r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)+1 AND r4.pre>r3.pre AND r4.post<r3.post AND r4.tg= ORDERED BY r4.pre Rell: level(n) = pre(n) post(n)+size(n) 76

(14) Given PRE/POST/SIZE tle, show SQL queries for the XPth queries ) /* ) ///* ) ///*// ) ///following-siling:: SELECT DISTINCT r4.pre FROM o_tl r1, r2, r3, r4 WHERE r1.pre=0 AND r2.pre>r1.pre AND r2.post<r1.post AND r2.tg= AND r3.pre<r2.pre AND r3.post>r2.post AND (r3.pre-r3.post+r3.size)=(r2.pre-r2.post+r2.size)-1 AND r4.pre>r2.pre AND r4.post<r3.post AND (r4.pre-r4.post+r4.size)=(r2.pre-r2.post+r2.size) AND r4.tg= ORDERED BY r4.pre prent of -noe fter efore prent sme level s Rell: level(n) = pre(n) post(n)+size(n) 77