Download presentation
Presentation is loading. Please wait.
Published byCamron Payne Modified over 9 years ago
1
k-d tree k-dimensional indexing
2
Jaruloj Chongstitvatana k-d trees 2 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.
3
Jaruloj Chongstitvatana k-d trees 3 Example 20,31 36,10 31,40 15,15 40,36 6,6 25,16
4
Jaruloj Chongstitvatana k-d trees 4 Insertion 20,31 36,10 31,40 15,15 40,36 6,6 25,16
5
Jaruloj Chongstitvatana k-d trees 5 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) }
6
Jaruloj Chongstitvatana k-d trees 6 Exact Search 20,31 36,10 31,40 15,15 40,36 6,6 25,16 (40, 36)
7
Jaruloj Chongstitvatana k-d trees 7 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) }
8
Jaruloj Chongstitvatana k-d trees 8 Range search 20,31 36,10 31,40 15,15 40,36 6,6 25,16
9
Jaruloj Chongstitvatana k-d trees 9 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.X, N)) then rangeSearch(T.leftChild, N) if (inRight(T.key.X, N)) then rangeSearch(T.rightChild, N) }
10
Jaruloj Chongstitvatana k-d trees 10 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
11
Jaruloj Chongstitvatana k-d trees 11 Deletion 36,10 38,40 15,15 40,36 32,1645,8 Delete the old pink point 28,5
12
Jaruloj Chongstitvatana k-d trees 12 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) }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.