Link to home
Start Free TrialLog in
Avatar of gudni12345
gudni12345

asked on

Semi - balanced binary tree.


How do I write a recursive algorithm that checks whether a binary search
tree is semi-balanced.


Avatar of ozo
ozo
Flag of United States of America image

balancedheight(node)::=
if node.isleaf then
 return 1
elseif balancedheight(node.left)>0 and balancedheight(node.rignt) > 0 and abs(balancedheight(node.left)-balancedheight(node.rignt)) <=1 then
  return 1+max(balancedheight(node.left),balancedheight(node.rignt)
else
  return 0

 
ASKER CERTIFIED SOLUTION
Avatar of theKashyap
theKashyap

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial