Sunday, December 16, 2018

Largest Binary Search Tree (BST), by Apple

December 16, 2018

Introduction


It is my first time to write a comment on my favorite algorithm called largest binary search tree.
Here is the blog's link.

My sharing


I finished all unlocked tree algorithms from easy to medium and hard this month. I really enjoy to solve a new algorithm called largest binary search tree. I will write something here later.

I wrote a comment in the following:

This one is my most favorite algorithm. Thank you for sharing. 

I just write a few comments based on my experience. 
1. Your algorithm time complexity is O(N), N is total number of nodes in tree, bottom up since post order is used in the traversal, most time efficient. Not top down. 
2. Every node is considered for the candidate as a root of binary search tree. Very good brute force idea to search maximum one. 
3. Base case is correct, one node is BST with value 1; Count nodes not edges. 
4. a tip to share, this algorithm is similar to Leetcode: longest univalue path.





No comments:

Post a Comment