Skip to main content
. 2015 Jun 19;15(6):14639–14660. doi: 10.3390/s150614639

Algorithm 2 Search algorithm of parallel hierarchical clustering tree

Input: T = {Ti|i = 1, 2,⋯, M}: hierarchical clustering trees;
1: Q: query point;
2: Lmax: maximum leaf size
Output: K nearest approximate neighbors of query point Q
3: L = 0 ⊲ L is the number of points searched
4: generate two empty priority queues Pf and Ps
5: for i = 1 → M do
6:  TraverseTree(Ti, Pf, Ps)
7: end for
8: while Pf is not empty and L < Lmax do
9: N = top of Pf
10:  TraverseTree(N, Pf, Ps)
11: end while
12:
13: function TraverseTree(N, Pf, Ps)
14: if node N is a leaf node then
15:   Search all the points in N and add them to Ps
16:   L = L + |N|
17: else
18:   C = child nodes of N
19:   Cq = closest node of C to query Q
20:   Cp = C\Cq ⊲ delete Cq from C
21:   Add all nodes in Cp to Pf
22:   TraverseTree(Cq, Pf, Ps)
23: end if
24: end function