Difference between revisions of "PrintAvlTree"

From CMSC 420
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Print the AVL-G Tree.
+
Prints the AVL-G Tree.
  
Takes no arguments, and merely prints the structure of your AVL-g tree using the rules from Section 7. This function is used to serialize your AVL-g tree so that its correctness can be checked.
+
== Parameters ==
 +
* (none)
 +
 
 +
== Possible ''<output>'' ==
 +
An <AvlGTree> node will be contained within the output tag and is the root of the AVL-g XML tree. This tag has three required attributes:
 +
* cardinality, whose value should be the size (number of keys) contained in the tree;
 +
* height, or the number of levels in the tree (a tree with levels 0 to w-1 has height w );
 +
* and maxImbalance, the maximum height difference between a node's left and right subtrees (in other words, g ).
 +
 
 +
* <node>: Represents a node in the AVL-g tree. This element has two attributes, key and value, which describe the key-value pair contained in the AVL node.
 +
 
 +
* <emptyChild>: Represents an empty subtree. This element has no attributes.
 +
 
 +
== Possible ''<error>'' types ==
 +
* emptyTree
 +
 
 +
== ''<success>'' Example ==
 +
<code>
 +
    <success>
 +
    <command name="printAvlTree"/>
 +
    <parameters/>
 +
    <output>
 +
      <AvlGTree cardinality="1" height="1" maxImbalance="3">
 +
        <node key="Baltimore" value="(140,37)">
 +
          <emptyChild/>
 +
          <emptyChild/>
 +
        </node>
 +
      </AvlGTree>
 +
    </output>
 +
  </success>
 +
</code>

Latest revision as of 20:49, 26 October 2013

Prints the AVL-G Tree.

Parameters[edit]

  • (none)

Possible <output>[edit]

An <AvlGTree> node will be contained within the output tag and is the root of the AVL-g XML tree. This tag has three required attributes:

  • cardinality, whose value should be the size (number of keys) contained in the tree;
  • height, or the number of levels in the tree (a tree with levels 0 to w-1 has height w );
  • and maxImbalance, the maximum height difference between a node's left and right subtrees (in other words, g ).
  • <node>: Represents a node in the AVL-g tree. This element has two attributes, key and value, which describe the key-value pair contained in the AVL node.
  • <emptyChild>: Represents an empty subtree. This element has no attributes.

Possible <error> types[edit]

  • emptyTree

<success> Example[edit]

   <success>
   <command name="printAvlTree"/>
   <parameters/>
   <output>
     <AvlGTree cardinality="1" height="1" maxImbalance="3">
       <node key="Baltimore" value="(140,37)">
         <emptyChild/>
         <emptyChild/>
       </node>
     </AvlGTree>
   </output>
 </success>