Amazon Interview Question
SDE-2sCountry: India
like below to find the nearest node in binary tree, similar could be done to get the nearest location between to point (x,y) in tree and (x1,y1) the point you are looking from. use some vector algebra.
tree* findNearestNumnew(tree* root, int num){
tree* cur = root;
tree* minnode = NULL;
int diff = INT_MAX;
while (cur != NULL){
if (diff > abs(cur->data - num)){
diff = abs(cur->data - num);
minnode = cur;
}
cur = (num < cur->data) ? cur->left : cur->right;
}
return minnode;
}
R-trees are tree data structures used for spatial access methods, i.e., for indexing multi-dimensional information such as geographical coordinates, rectangles or polygons.
- Atul12 March 04, 2016