We strongly recommend to refer below post as a prerequisite of this.
In this post find minimum is discussed. The operation is to find minimum in the given dimension. This is especially needed in delete operation.
For example, consider below KD Tree, if given dimension is x, then output should be 5 and if given dimensions is t, then output should be 12.
In KD tree, points are divided dimension by dimension. For example, root divides keys by dimension 0, level next to root divides by dimension 1, next level by dimension 2 if k is more then 2 (else by dimension 0), and so on.
To find minimum we traverse nodes starting from root. If dimension of current level is same as given dimension, then required minimum lies on left side if there is left child. This is same as Binary Search Tree Minimum.
Above is simple, what to do when current level’s dimension is different. When dimension of current level is different, minimum may be either in left subtree or right subtree or current node may also be minimum. So we take minimum of three and return. This is different from Binary Search tree.
Below is C++ implementation of find minimum operation.
Minimum of 0'th dimension is 5 Minimum of 1'th dimension is 12
This article is contributed by Ashish Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Tournament Tree (Winner Tree) and Binary Heap
- AVL Tree | Set 1 (Insertion)
- AVL Tree | Set 2 (Deletion)
- Find the k most frequent words from a file
- Pattern Searching using Suffix Tree
- Ternary Search Tree
- Segment Tree | Set 1 (Sum of given range)
- Segment Tree | Set 2 (Range Minimum Query)
- B-Tree | Set 2 (Insert)
- B-Tree | Set 1 (Introduction)
- Find all possible interpretations of an array of digits
- B-Tree | Set 3 (Delete)
- Splay Tree | Set 1 (Search)
- Splay Tree | Set 2 (Insert)
- Find LCA in Binary Tree using RMQ
Improved By : mayurpothuri