Skip to main content
. 2014 Jul 21;14(7):12990–13005. doi: 10.3390/s140712990
Algorithm 2. Pseudo code of node-choosing sub-algorithm.

Algorithm 2 Description: node-choosing sub-algorithm (pick out one node at Level 1, into which TNode will be inserted)

Input: TNode (leaf node to insert into R-tree), Root (the root of R-tree)
Output: a level-one node (considered as the father of TNode)

1. NodeSet.Clear()            : temporal node set is cleared off
2. MinLevelID → Root.LevelID + 1     : let MinLevelID be tree depth initially
3. Father → Root           : let Father be Root
4. SeqArray[Father.LevelID] → 0;      : let the Father.LevelIDth item in SeqArray be 0
5. While Father != NULL Do
6. Node → Father.IthChild (SeqArray[Father.LevelID])     : let the ith child of Father be the current node
7. If Node.Contain(TNode) = True Then     : if Node contains TNode
8. If Node.LevelID = MinLevelID Then     : if level number of Node is equal to MinLevelID
9. NodeSet.Add(Node)     : add Node in NodeSet
10. Else If Node.LevelID < MinLevelID Then     : if level number of Node is less than MinLevelID
11. NodeSet.Clear()     : clear NodeSet
12. NodeSet.Add(Node)     : add Node in NodeSet
13. MinLevelID → Node.LevelID     : let MinLevelID be level number of Node
14. End If
15. If Node.LevelID > 1 Then     : if level number of Node is greater than 1, enter the lower level
16. Father → Node     : let Father be Node
17. SeqArray[Father.LevelID] → 0     : let the corresponding item in SeqArray 0
18. Continue Loop     : restart new loop
19. End If
20. End If
21. If Node.LevelID = 1 Or Node.Contain(TNode) = False Then     : if Node is at level 1 or Node doesn't contain Leaf
22. SeqArray[Father.LevelID] → SeqArray[Father.LevelID] + 1     : move to next child node
23. While SeqArray[Father.LevelID] = Father.NumChildren Do     : if finish traversing all child nodes
24. Father → Father.ParentNode     : backspace to upper level
25. If Father = NULL Then     : if finish traversing all child nodes of Root
26. Break Loop     : exit loop
27. End If
28. SeqArray[Father.LevelID] → SeqArray[Father.LevelID] + 1     : start traversing the right sibling
29. End While
30. End If
31. End While
32. If NodeSet.IsEmpty() = True Then     : if NodeSet is null, there is no node to contain TNode
33. NewRoot → Root     : let NewRoot be Root
34. Else If MinLevelID = 1 Then     : if there exist the required nodes at level 1
35. NewRoot → LargestNode(NodeSet)     : let NewRoot be the largest node in NodeSet
36. Else
37. Set is the collection of child nodes of all nodes in NodeSet. In Set, choose a node which will change the least after containing TNode. Let NewRoot be the node
38. End If
39. In the sub-tree whose root is NewRoot, search for a node in level 1 by classical node choosing algorithm.
40. Output the node. Exit