Binary Search Tree (BST): Validator Function

Поделиться
HTML-код
  • Опубликовано: 3 янв 2025

Комментарии • 23

  • @brianwahome5789
    @brianwahome5789 7 лет назад +4

    I also got to apply this in a recent interview. I used an inorder traversal with no repeats and increasing order as my checks. All logic from the print function you taught me. It worked like a charm. Your work is simply amazing man.

    • @BrianFaure1
      @BrianFaure1  7 лет назад +1

      Glad to hear it Brian! Thanks for the support!

  • @siddhantbhardwaj4268
    @siddhantbhardwaj4268 3 года назад

    Excellent video, understood it very clearly !! Thank You !!

  • @brianwahome5789
    @brianwahome5789 7 лет назад +9

    You heeded my request!! Thank you sir!!!!!!

  • @roblevintennis
    @roblevintennis 4 года назад +1

    You really did a great job with this video from both your explanations to the overall clarity and production. Thanks for putting forth this effort-really helpful Brian!
    It should probably also be mentioned that this can be solved iteratively if you use a Queue and basically keep a pointer to the previous value as you do an inorder traversal, since in a valid BST, that should produce a sorted list essentially. If ever you encounter that previous > current you return False. I think the recursive solution you have here and the inorder approach are the common ones for this problem and I've been using algoexpert, the elements of programming interviews in python book amongst other resources, so your solution is definitely a perfect recursive solution...nice to see accurate instruction sir! Thanks again :)

  • @mohamedatef8483
    @mohamedatef8483 7 лет назад +1

    can you please keep going with this series
    i wanna understand stacks queues and another algorithms like graph , trees and dynamic programming
    and thanks for your effort
    thanks a lot

    • @BrianFaure1
      @BrianFaure1  7 лет назад

      Hi Mohamed, thanks for the kind words! I'm actually working on a video for AVL trees right now, and I just got a new mic so the audio quality should be much better. I'll throw your suggestions on the list too, I think stacks and queues would be really interesting topics to cover.

    • @tolulopeadetula4777
      @tolulopeadetula4777 6 лет назад

      And Graphs also. Your explanations are simple and easy to understand

  • @parikothari5654
    @parikothari5654 4 года назад

    This very useful :) would you also do traversal methods and if binary tree is full or not?

  • @longhornfinch
    @longhornfinch 7 лет назад +1

    I have a question, Python 3 does not allow sys.maxint anymore. I am not sure if sys.maxsize will have same impact as this one. Does hard setting it to a 64bit Int works?

    • @BrianFaure1
      @BrianFaure1  7 лет назад +1

      If you'd like an easy swap 'sys.maxsize' should provide the same value as 'maxint' on the same system with similar installations, though you should also be able to hard code it. You basically just want a value that's larger than (and smaller than when negative) any value you could possibly see in the tree. The problem with any implementation in Python is that when you go above the value spit back by 'sys.maxint' your int will seamlessly be transformed into a long so it's value can be essentially limitless given plenty of memory. Meaning we can't really put bounds on elements we might see in the tree unless we add in a check to ensure they are of the integer type.

  • @_sls7535
    @_sls7535 4 года назад +2

    if you want to avoid importing sys you could use float('-inf') as minimum and float('inf') as maximum

  • @shantanusharma5617
    @shantanusharma5617 7 лет назад +1

    Really awesome videos Brian. Can you also do something on AVL(balanced BST) trees? Thanks, keep these videos coming. :D

    • @BrianFaure1
      @BrianFaure1  7 лет назад

      sure thing! thanks for watching

  • @subhamoypaul7029
    @subhamoypaul7029 6 лет назад

    please do a video on Heap data structure!

  • @looneytoons2006
    @looneytoons2006 5 лет назад

    thnx !!!

  • @vijaygr427
    @vijaygr427 7 лет назад

    Thank you so much ,Nice video.
    But if i use this function with our previous binarysearchtree ,i am getting error like
    if( root.value >min and
    6 root.value < max and
    7 validate(root.left,min,root.value)and
    AttributeError: 'BST' object has no attribute 'value'
    because here i this function its geting root value from Node class .but in our BST implementation we are creating object for
    BST class ,so BST object has no access to Node class value . Help me to fix this plz

    • @BrianFaure1
      @BrianFaure1  7 лет назад +1

      Hi Vijay! To use this function with our prior BST class you need to pass the root of the BST as the parameter to the function (so validate_bst(a.root), where 'a' is the name of the BST instance, for example). I should have specifically said this in the video, sorry for the confusion.

    • @mathiasschmidt468
      @mathiasschmidt468 3 года назад

      @@BrianFaure1 You are A.W.E.S.O.M.E !!

  • @tolulopeadetula4777
    @tolulopeadetula4777 6 лет назад +1

    This doesn't take care of if the root.value is == max i.e root.value = 5, root.left=2 and root.right = 5