Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3.) For a binary search tree T of n nodes, determine the number of internal node

ID: 3726757 • Letter: 3

Question

3.) For a binary search tree T of n nodes, determine the number of internal nodes in O(n) running time in psuedo code.

(1) Give a recursive algorithm.

(2) Give a non-recursive algorithm.

Explanation / Answer

--> recursive version function GetInternalNodeCount(root) if root is null return 0 else count = 0 if left_child is not null or right_child is not null count=1 end if return count + GetInternalNodeCount(left_child) + GetInternalNodeCount(right_child) end if end function --> non-recursive version function GetInternalNodeCount(root) count = 0 queue = [root] while queue is not empty node = queue.pop_node() if node is not null if left_child is not null or right_child is not null count = count+1 queue.add(left_child) queue.add(right_child) end if end if end if end function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote