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 y, 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 1 (Search and Insert)
- K Dimensional Tree | Set 3 (Delete)
- Two Dimensional Segment Tree | Sub-Matrix Sum
- Convert a Generic Tree(N-array Tree) to Binary Tree
- Van Emde Boas Tree | Set 2 | Insertion, Find, Minimum and Maximum Queries
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Segment Tree | Set 2 (Range Minimum Query)
- Proto Van Emde Boas Tree | Set 5 | Queries: Minimum, Maximum
- Query to find the maximum and minimum weight between two nodes in the given tree using LCA.
- Tournament Tree (Winner Tree) and Binary Heap
- Binary Indexed Tree or Fenwick Tree
- Difference between B tree and B+ tree
- Build a segment tree for N-ary rooted tree
- Interval Tree using GNU Tree-based container
- Order statistic tree using fenwick tree (BIT)
- Find minimum y coordinates from set of N lines in a plane
- Iterative Segment Tree (Range Minimum Query)
- Minimum Bottleneck Spanning Tree(MBST)
- Second minimum element using minimum comparisons