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)
- K Dimensional Tree | Set 1 (Search and Insert)
- Two Dimensional Segment Tree | Sub-Matrix Sum
- Find maximum (or minimum) in Binary Tree
- Find Minimum Depth of a Binary Tree
- Find the node with minimum value in a Binary Search Tree
- Sub-tree with minimum color difference in a 2-coloured tree
- Minimum swap required to convert binary tree to binary search tree
- 4 Dimensional Array in C/C++
- Dimensional Data Modeling
- C#| How to change the size of one-dimensional array
- Sorting a dynamic 2-dimensional array of Strings
- Minimum Product Spanning Tree
- Kruskal's Minimum Spanning Tree using STL in C++
Improved By : mayurpothuri