Consider the pseudo code: [code] int avl(binarysearchtree root): if(not root) return 0 left_tree_height = avl(left_of_root)

Phạm Quyết

New member
Consider the pseudo code:
Code:
  int avl(binarysearchtree root):
     if(not root)
       return 0
     left_tree_height = avl(left_of_root)
     if(left_tree_height== -1) 
       return left_tree_height
     right_tree_height= avl(right_of_root)
     if(right_tree_height==-1)
       return right_tree_height
Does the above code can check if a binary search tree is an AVL tree?
A. yes
B. no
 
Answer: A
Explanation: The condition to check the height difference between left and right subtrees is missing. if (absolute(left_tree_height – right_tree_height)>1) must be added.
 

Tìm kiếm

Back
Top