1 / 2

Neither!

Neither!. // Imbalance of a BST defined to be the absolute difference // between depth of its left and right subtrees. public static int imbalance( BSTnode bn ) { return Math.abs( Depth ( bn.left )- Depth ( bn.right )); }

neka
Download Presentation

Neither!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Neither!

  2. // Imbalance of a BST defined to be the absolute difference// between depth of its left and right subtrees public static int imbalance(BSTnodebn) {return Math.abs(Depth(bn.left)-Depth(bn.right)); } public static int Depth(BSTnodebn) {if(bn == null) return 0;return Math.Max(Depth(bn.left), Depth(bn.right))+1; } What is the complexity of this algorithm? This algorithm visits every node once, so complexity is O(n)

More Related