Docsity

Binary Trees: Generating Functions and Tree Traversals, Slides of Data Structures and Algorithms

Partial preview of the text

Download Binary Trees: Generating Functions and Tree Traversals and more Slides Data Structures and Algorithms in PDF only on Docsity!

  • Binary Trees

Apparently, b 1 is 1, and b 2 is 2. The b 0 coefficient is somewhat artificial, its the no-nodes tree which is, I guess, the only one. Further analysis gives the following idea: if a binary tree has n nodes, then there must be one node as the root and two subtrees. The total number of nodes in the subtrees must be n- 1 , and either of them may be empty. Assuming k nodes in the left subtree, the right subtree then has n-k- 1 nodes, k going from 0 to n- 1. The root node is always there, and therefore the tree configurations differ only by the configuration of subtrees.

The total number of possible trees on n nodes can then be expressed as:

About level order

While loop only if the tree is not empty Following the addition of the children of t to the queue,we attempt to delete an element from the queue. If the queue is empty,Delete throws an OutOfBounds exception. If the queue is not empty,then Delete returns the deleted element in t.