Showing posts with label kd tree. Show all posts
Showing posts with label kd tree. Show all posts

Aug 1, 2009

Given a set of points (x,y) on a 2D coord system, identify list of 2D coords that are of distance less than x units long.

Given a set of points (x,y) on a 2D coord system, identify list of 2D coords that are of distance less than x units long.
Eg.
Let x = 1;
Given (0,0), (0,1), (1, 2), (4,6);
Return 1 -> (0,0), (0,1)
Build the kd tree, iteratively find the neighbors for the node where the distance is less than 1
http://en.wikipedia.org/wiki/Kd-tree#Nearest_neighbor_search
foo(tree* root, tree* node, stack s,int len)
{
if(!root) return;
if(DIS(root,node)<(-1*len))
foo(root->left,node,s,len);
else if(DIS(root,node)>len))
foo(root->right,node,s,len);
else
{ if(!root->left&&!root->right)//left node is the point node
{
s.push(root);
return;
}
foo(root->left,node,s,len);
foo(root->right,node,s,len);
}
}

Feb 12, 2009

KD tree search

Given a set of points (x,y) on a 2D coord system, identify list of 2D coords that are of distance less than x units long.
Eg.
Let x = 1;
Given (0,0), (0,1), (1, 2), (4,6);
Return 1 -> (0,0), (0,1)
Build the kd tree, use the range where the radius is unit long originated from anyone point to search on the kd tree, get a subset of points. Do the iteratively search on the subset…

Dec 29, 2008

having 1 million customer addresses, how to store and search them efficiently. Suppose you can search the address by phone number or name or account n

having 1 million customer addresses, how to store and search them efficiently. Suppose you can search the address by phone number or name or account number. My response is to use a hashtable with phone number as the key and address as the value. But how to implement multiple keys to the same value? Any other options?

Use kd tree to partition the address, 3 dimensions are phone number, name and account number