Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm assuming you're either coding in C or C++.</p> <p>a. A node, if the structure is defined like this: struct node { struct node *left, *right; }; You can observe that the structure can either have 0, 1, or 2 leaves. So, the max is 2, min is 0 leaves.</p> <p>b.Minimal height is zero, in which would only contain the root node. Note that the root node does not count as a height of 1. It's also called depth at times. Here is an algorithm for the height:</p> <pre><code> int height(struct node *tree) { if (tree == NULL) return 0; return 1 + max (height (tree-&gt;left), height (tree-&gt;right)); } </code></pre> <p>Read more: <a href="http://wiki.answers.com/Q/How_do_you_find_out_the_height_of_a_Binary_Search_Tree#ixzz1NIB17SkL" rel="nofollow">http://wiki.answers.com/Q/How_do_you_find_out_the_height_of_a_Binary_Search_Tree#ixzz1NIB17SkL</a></p> <p>c. Pardon me if I take this the worng way, but I'm assuming if we mapped this out on a piece of paper, we'd be trying to find the number of "links" that we would use? In that case, it'd simply be the number of nodes in the tree -1 for root node. This algorithm found on this page <a href="http://forums.techarena.in/software-development/1147688.htm" rel="nofollow">http://forums.techarena.in/software-development/1147688.htm</a> can help you: check if root is null, then pass the left and right nodes as parameters into the function.</p> <pre><code>int countnodes(Node* root) { if (root == null || k&lt;=0) { return 0; } else { return 1 + count(root.left,k-1) + count(root.right,k-1); } } // remember to subtract one at the end. int totalnodes = countnodes(root) - 1; </code></pre> <p>d. The time complexity for best case is O(nlogn) where n is the number of nodes to insert. The worst case, is O(n). It is directly linear. </p> <p>If you have any other questions just google it, there's plenty of things to know about binary search trees. But most of it is simply recursion that you can learn in 30 seconds.</p> <p>I hope this helps. Good luck on your exam! I had mine a few months ago. ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload