Julie Heiser
April 30, 2001 Software Pattern |
RECURSION (in tree data structures)* int computeNumNodesBelowCurrentNode (Node n) { return totalNumNodes;
found in network classification algorithms, A tree is a group of nodes sharing the same root node or origin. A node is an object that could contain two child nodes, if the node is a parent node, it contains at least one child node. A leaf is a node containing no children, or an empty node. When someone is setting up a router they need to store rules that will be used to route data traffic. These rules could be stored in a tree like structure, such as discussed in the preceding paragraph, where the rules are stored in the nodes of the tree. The rules that can be tored in the nodes are IP addresses, protocols, port numbers, etc. The recursion program can calculates the number of nodes in a tree. this is very important, as it is a common calculation in computer programming, software and hardware. For example, If each node tores a rule, and one needs to know how much memory one needs in order to store the tree data structure, the recursion program is an efficient way of assessing that information. The ingredients/instructions for programming a successful recursion program (specific to the tree data structure problem) are: Set current Node to be Root Node 0) If current Node does not have any children, return 1. 1) If current Node has Left Node, set current Node to Be Left Child Node and return number of nodes below Left Child Node (current node). 2) Do the same instruction 2) for Right Child Node and return number of nodes below. 3) Add results from 2) and 3) and return this total Number of nodes as the size of the tree.
Therefore: In dealing with the problem of determining the size of the tree data structure it is most efficient for programmers to use recursion to find the solution. *** Programming languages, networking, data structures, internet routing, software engineering. |