Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Present. Outline Index structures for in-memory Quad trees kd trees Index structures for databases kdB trees Grid files 23014742II. Index Structure.

Similar presentations


Presentation on theme: "The Present. Outline Index structures for in-memory Quad trees kd trees Index structures for databases kdB trees Grid files 23014742II. Index Structure."— Presentation transcript:

1 The Present

2 Outline Index structures for in-memory Quad trees kd trees Index structures for databases kdB trees Grid files 23014742II. Index Structure for One-dimensional Data

3 Quad Trees, kD Trees 23014743II. Index Structure for One-dimensional Data

4 2301474II. Index Structure for One-dimensional Data4

5 Point Quadtrees Point quad trees always split regions into 4 parts In a 2-d tree, a node N splits a region into two by drawing one line through the point (N.XVAL,N.YVAL) In a point quadtree, a node N splits the region it represents by drawing both horizontal and vertical line through the point (N.XVAL,N.YVAL) These 4 parts are called the NW, SW, NE, SE quadrants determined by node N; each of these corresponds to a child of N.

6 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

7 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

8 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

9 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

10 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

11 Insertion into Point Quadtrees City (XVAL,YVAL) Banja Luka (19,45) Derventa (40,50) Toslic (38,38) Tuzla (54,35) Sinj (4,4)

12 Deletion in Point Quadtrees If the node being deleted is a leaf node, deletion is trivial: we just set the appropriate link filed of node N’s parent to NIL and return node to storage otherwise, as in the case of 2-d trees, we need to find an appropriate replacement node

13 Deletion in Point Quadtrees When deleting an interior node N, we must find a replacement node R in one of the subtrees of N such that every other node R 1 in N.NW is to the northwest of R every other node R 2 in N.SW is to the southwest of R every other node R 3 in N.NE is to the northeast of R every other node R 4 in N.SE is to the southeast of R N R

14 Deletion in Point Quadtrees In general, it may not always be possible to find such a replacement node deletion of an interior node N may require reinsertion of all nodes in the subtrees of N In the worst case, this may require almost all nodes to be reinserted

15 Range Searches in Point Quadtree Similar to that of 2-d trees each node in a point quadtree represents a region do not search regions that do not intersect the circle defined by the query

16 Region Quadtree Representing image 2301474II. Index Structure for One-dimensional Data16 1 23 45 1314 191112 6 15 1817 16 7 109 8 A BCF 2 1 34561112 D 131419 E 15161718 78910 NW NE SW SE

17 2301474II. Index Structure for One-dimensional Data17

18 Jaruloj Chongstitvatanak-d trees18 Definition Let k be a positive integer. Let t be a k-d tree, with a root node p. Then, for any node n in t with the key K j as a discriminator: The value of K j of any node q in the left subtree of n is smaller than that of node p, The value of K j of any node q in the right subtree of n is larger than that of node p.

19 Jaruloj Chongstitvatanak-d trees19 Example 20,31 36,10 31,40 15,15 40,36 6,6 25,16

20 Jaruloj Chongstitvatanak-d trees20 Insertion 20,31 36,10 31,40 15,15 40,36 6,6 25,16

21 Jaruloj Chongstitvatanak-d trees21 Insertion Algorithm insert(subtree T, node N) /* T is the root node of a subtree, including the dividing axis, and N is the structure of the node to be inserted including its key values */ {if (T.axis is ‘X’) if (T.key.X > N.key.X) then if (T is leaf) then addLeftChild(T, N) else insert(T.leftChild, N) else if (T is leaf) then addRightChild(T, N) else insert(T.rightChild, N) elseif (T.key.Y > N.key.Y) then if (T is leaf) then addLeftChild(T, N) else insert(T.leftChild, N) else if (T is leaf) then addRightChild(T, N) else insert(T.rightChild, N) }

22 Jaruloj Chongstitvatanak-d trees22 Exact Search 20,31 36,10 31,40 15,15 40,36 6,6 25,16 (40, 36)

23 Jaruloj Chongstitvatanak-d trees23 Search Algorithm search(subtree T, node N) //T is the root node of a subtree, including the dividing axis, and //N is the structure of the node including its key values to be searched {if (equal(T, N) then return(T). if (T.axis is ‘X’) {if (T.key.X > N.key.X) then search(T.leftChild, N) else search(T.rightChild, N) } elseif (T.key.Y > N.key.Y) then search(T.leftChild, N) else search(T.rightChild, N) }

24 Jaruloj Chongstitvatanak-d trees24 Range search 20,31 36,10 31,40 15,15 40,36 6,6 25,16

25 Jaruloj Chongstitvatanak-d trees25 Range Search Algorithm rangeSearch(subtree T, box N) // T is the root node of a subtree, including the dividing axis, and //N is the structure of the box including its two opposite corner points {if (T is null) then return. if (in(T, N) then print(T). if (T.axis is ‘X’) if (inLeft(T.key.X, N)) then rangeSearch(T.leftChild, N) if (inRight(T.key.X, N)) then rangeSearch(T.rightChild, N) elseif (T.key.Y > N.key.Y) if (inLeft(T.key.Y, N)) then rangeSearch(T.leftChild, N) if (inRight(T.key.Y, N)) then rangeSearch(T.rightChild, N)}

26 Jaruloj Chongstitvatanak-d trees26 Deletion 20,31 36,10 38,40 15,15 40,36 32,16 28,5 45,8 Delete the blue pointCopy the pink point up

27 Jaruloj Chongstitvatanak-d trees27 Deletion 36,10 38,40 15,15 40,36 32,1645,8 Delete the old pink point 28,5

28 Jaruloj Chongstitvatanak-d trees28 Deletion Algorithm delete(subtree T, node N) // T is the root node of a subtree, including the dividing axis, and //N is the structure of the node including its key values to be deleted {D = search(T, N). if ( D is not null) {S = next(T, D) delete(S, T) replace(D, S) }

29 kdB trees, Grid Files 2301474II. Index Structure for One-dimensional Data29

30 2301474II. Index Structure for One-dimensional Data30

31 Jaruloj Chongstitvatana 2006K-D-B Tree31 Characteristics Multi-way branch Height-balanced tree Repeatedly divide area of the domain into disjoint sub-area A node in a tree corresponds to a (set of consecutive) disk page(s)

32 Jaruloj Chongstitvatana 2006K-D-B Tree32 Example of Data Records Table (stdntID, courseID, grade, year, smstr) Table (accID, branchID, saving, name, addr) Table (custID, age, gender, occupation, salary, children, promotion, since)

33 Jaruloj Chongstitvatana 2006K-D-B Tree33 Nodes = Pages Region pages Contain a set of Internal nodes Point pages Contain a set of Leaf nodes

34 Jaruloj Chongstitvatana 2006K-D-B Tree34 Region Pages XmaxXminYmaxYmin PAGE XmaxXminYmaxYmin … PAGE Region The branching factor is determined by the page size and the size of each entry.

35 Jaruloj Chongstitvatana 2006K-D-B Tree35 Point Pages XY DATA RECORD XY XY … POINT The branching factor of a point page is usually larger than that of a region page.

36 Jaruloj Chongstitvatana 2006K-D-B Tree36 Example Point page

37 Jaruloj Chongstitvatana 2006K-D-B Tree37 Search Point page Point query

38 Jaruloj Chongstitvatana 2006K-D-B Tree38 Insert Insert a point here and the point page overflows.

39 Jaruloj Chongstitvatana 2006K-D-B Tree39 Split Split a region r with page id p along x i If r is on the right/left page of x i then put in the right/left page. Otherwise; For each children p c of p, split p c along x i Split r along x i into r left and r right. Create 2 new pages with page id p left and p right. Move children of p in the left region into p left and children in the right region into p right. Return and.

40 Jaruloj Chongstitvatana 2006K-D-B Tree40 Split: Example The page overflows, and is splitted. This region is splitted. This region is also splitted.

41 Jaruloj Chongstitvatana 2006K-D-B Tree41 Split: Example The region page is splitted. The point page is also splitted. Create a new region page.Children pages are transferred.

42 Jaruloj Chongstitvatana 2006K-D-B Tree42 How to find split axis Cyclic: x -> y -> x -> y -> … Priority: x -> x -> y -> x -> x -> y -> … Possible one

43 Jaruloj Chongstitvatana 2006K-D-B Tree43 Insert Insert a record with point a and location l in a tree with root r If r is NIL, then create a point page p and insert the record with in p and return p. Otherwise; Search for a in the tree with root r until a point page, say p, is reached. Insert the record in the point page p.

44 Jaruloj Chongstitvatana 2006K-D-B Tree44 Insert (cont’d) Insert a record with point a and location l in a tree with root r If the point page p is overflowed, then find an appropriate axis to split p into p left and p right. If p is not the root, then change to p and p left, and insert p right into the parent of p. If p is the root, then create a new root node with two children of p left and p right.

45 Jaruloj Chongstitvatana 2006K-D-B Tree45 Insert: Example Insert here and split point page if overflows. Divide region. Search for the given point until the point page is found.

46 Jaruloj Chongstitvatana 2006K-D-B Tree46 Insert: Example Parent page overflows, then split the page. This region is splitted.

47 Jaruloj Chongstitvatana 2006K-D-B Tree47 Insert: Example The point page is splitted. The region page is splitted.

48 Jaruloj Chongstitvatana 2006K-D-B Tree48 Insert: Example Insert the new region page in its parent.The root node is overflowed, and then splitted.

49 Jaruloj Chongstitvatana 2006K-D-B Tree49 Insert: Example Create the new root node

50 Jaruloj Chongstitvatana 2006K-D-B Tree50 Delete Simple, if storage utilization is ignored. Otherwise, an underfull page should be merged with another page. When 2 pages are merged, the region of the new page must be a valid region. A number of regions are joinable if their union is also a region.

51 Jaruloj Chongstitvatana 2006K-D-B Tree51 Joinable Regions

52 Jaruloj Chongstitvatana 2006K-D-B Tree52 Unjoinable Regions

53 Jaruloj Chongstitvatana 2006K-D-B Tree53 Delete (cont’d) If a page p is underfull, merge sibling pages of p whose regions are joinable. If the newly-created page is overflowed, then split the page.

54 2301474II. Index Structure for One-dimensional Data54

55 Jaruloj Chongstitvatana 2006Grid Files55 Properties of Grid Files Support multi-dimensional data, but not high-dimension. Every key is treated as primary key. The index structure adapts itself dynamically to maintain storage efficiency. Guarantee two disk accesses for point queries Values of key must be in lineraly-ordered domain.

56 Jaruloj Chongstitvatana 2006Grid Files56 Structure of Index Structure Grid directories: for k-dimensional data Grid array A k-dimensional array Each element is a pointer to a data page Linear scales k 1-dimensional array Each array defines the partition of values in each dimension. Data buckets/ pages

57 Jaruloj Chongstitvatana 2006Grid Files57 Grid Directory Grid array Pointers to data buckets/pagesLinear scales

58 Jaruloj Chongstitvatana 2006Grid Files58 Point Query X Y 0 6 25 32 A F K O Z Find x=9 and y=“Rat”

59 Jaruloj Chongstitvatana 2006Grid Files59 Range Query X Y 0 6 25 32 A F K O Z Find 5<x<9 and “Mat”<y<“Rat”

60 Jaruloj Chongstitvatana 2006Grid Files60 Insertion Overflow, then split the region Update the linear scaleAlso, split the data page

61 Jaruloj Chongstitvatana 2006Grid Files61 Insertion Overflow, then split the regionOnly the overflowed data page is split Update linear scale This data page is not split.

62 Jaruloj Chongstitvatana 2006Grid Files62 Insertion The data page is overflowed, but the directory is notTherefore, split only the data page

63 Jaruloj Chongstitvatana 2006Grid Files63 Insertion

64 Jaruloj Chongstitvatana 2006Grid Files64 Merging A CD B FE ECDF AB 1 3 2 1 2 3

65 Jaruloj Chongstitvatana 2006Grid Files65 Deletion A CD B FE EC D F AB Merge data pages A and B, but directory pages cannot be merged yet. Merge does not occur Delete point

66 Jaruloj Chongstitvatana 2006Grid Files66 Deletion A CD B FE EC D F AB Merge data pages D and F. Directory pages are also merged. Delete point

67 Jaruloj Chongstitvatana 2006Grid Files67 Deletion AB DFCE DF AB Merge data pages CE and DF. Directory pages are also merged. Delete point

68 THE END 2301474II. Index Structure for One-dimensional Data 68


Download ppt "The Present. Outline Index structures for in-memory Quad trees kd trees Index structures for databases kdB trees Grid files 23014742II. Index Structure."

Similar presentations


Ads by Google