Have written a Binary Search Tree that stores data on ships, the key for the search is their acoustic signature.
When searching the tree I want to return either a ship with the correct signature or the one with the closest match to the searched signature. (By seeing which ship has the closest Euclidean distance).
The problem I am having is how to compare the signatures other than their actual numerical value. Which would then mean that any search performed would be sequential and not binary?
Any ideas?
What you’re doing comes down to a nearest-neighbour search in multiple dimensions. You can’t solve this efficiently with just a binary tree; you’ll need some space partitioning structure.
If your array length N is small (single digits), you can use a 2^N-ary tree (quadtree, octree, …) as a generalization of a binary tree.
A popular choice which also works well for higher dimensions is a Kd-tree.