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
- Two Dimensional Binary Indexed Tree or Fenwick Tree
- K Dimensional Tree | Set 3 (Delete)
- Two Dimensional Segment Tree | Sub-Matrix Sum
- K Dimensional Tree | Set 1 (Search and Insert)
- Segment Tree | Set 2 (Range Minimum Query)
- Iterative Segment Tree (Range Minimum Query)
- Find LCA in Binary Tree using RMQ
- Queries to find distance between two nodes of a Binary tree
- Queries to find distance between two nodes of a Binary tree - O(logn) method
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Tournament Tree (Winner Tree) and Binary Heap
- Binary Indexed Tree or Fenwick Tree
- Order statistic tree using fenwick tree (BIT)
- Second minimum element using minimum comparisons
- Introduction to R-tree
Improved By : mayurpothuri