Boundary traversal of binary tree (Border Elements)

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Find all the nodes on the boundary and print them. That is the boundary order traversal of binary tree.

КОМЕНТАРІ • 42

  • @surajjha5542
    @surajjha5542 6 років тому +28

    Nice video , just a minor correction : print root node first and then pass root's left to the print_left function .
    Otherwise it will fail for a tree having only right nodes.

  • @CodeSuccessChronicle
    @CodeSuccessChronicle 3 роки тому +2

    The way he says Hello friends itself takes my anxiety away.. Thank you for your efforts.

  • @meghasharma3092
    @meghasharma3092 4 роки тому +1

    Just can't tell , how good you are ! Your videos have been really helpful for me in preparing for data structures interviews..! :)

  • @arpitgupta1143
    @arpitgupta1143 5 років тому +6

    Your explanation is nice... but if the tree is skewed it will print the boundary elements multiple times.

  • @aakashparmar560
    @aakashparmar560 3 роки тому

    Sir just want to say thank you for this wonderful video. You are OP sir...........

  • @JJ-Bond
    @JJ-Bond 5 років тому

    this is a very great explanation, I appreciate all of your videos.
    a small thing
    1. root needs to be dealt with independently before process left and right subtree

  • @minirasamedova648
    @minirasamedova648 3 роки тому

    You are genius!! Thank you so much for a simple explanation

  • @kasyapdharanikota8570
    @kasyapdharanikota8570 3 роки тому

    very well explained sir, thank you for detailed explanation

  • @Algo_Guru
    @Algo_Guru 4 роки тому +1

    Hi Vivekanand, very clear explanation..Thanks. One request, could you please also mention some use cases (applications) of each of the traversals? This would motivate the viewers.

  • @sandeepsinghnegi3644
    @sandeepsinghnegi3644 6 років тому +14

    can you make a series on solving the competitive programming question

  • @karthikrashinkar204
    @karthikrashinkar204 3 роки тому +2

    Can I say that we need to find
    1) left view of binary tree
    2) right view of binary tree
    3) find leaf nood of binary tree ?

  • @AlancRodriguez
    @AlancRodriguez 3 роки тому

    Superb explanation!

  • @chrisy.703
    @chrisy.703 2 роки тому

    really really good man!

  • @edwardteach2
    @edwardteach2 2 роки тому

    Thanks, my python implementation:
    # Definition for a binary tree node.
    # class TreeNode(object):
    # def __init__(self, val=0, left=None, right=None):
    # self.val = val
    # self.left = left
    # self.right = right
    class Solution(object):
    def __init__(self):
    self.root = []
    self.lb = []
    self.rb = []
    self.leaves = []
    def boundaryOfBinaryTree(self, root):
    """
    :type root: TreeNode
    :rtype: List[int]
    """
    if not root:
    return root
    self.root.append(root.val)
    self.left_bdr(root.left)
    self.leaf(root.left)
    self.leaf(root.right)
    self.right_bdr(root.right)
    return self.root + self.lb + self.leaves + self.rb[::-1]
    def left_bdr(self, root):
    if root:
    if root.left:
    self.lb.append(root.val)
    self.left_bdr(root.left)
    elif root.right:
    self.lb.append(root.val)
    self.left_bdr(root.right)
    def right_bdr(self, root):
    if root:
    if root.right:
    self.rb.append(root.val)
    self.right_bdr(root.right)
    elif root.left:
    self.rb.append(root.val)
    self.right_bdr(root.left)
    def leaf(self, root):
    if root:
    self.leaf(root.left)
    self.leaf(root.right)
    if not root.left and not root.right:
    self.leaves.append(root.val)

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 4 роки тому +1

    Nice video,also please mention Time complexity for algorithm

  • @amitranjan6998
    @amitranjan6998 2 роки тому

    in the left tree recursion ,if e finishes the recursion stack then after some time it go back to C and from C it look ,it's have right subtree or not ,it have so it add C again

  • @roshanraut3093
    @roshanraut3093 4 роки тому +1

    Requires to change the position of print in print_right function.

  • @harshanand4018
    @harshanand4018 3 роки тому

    In Right Boundary Condition,there is a correction. First we need to traverse to right child and then print the data.

  • @user-mo1vm2nt7l
    @user-mo1vm2nt7l 5 років тому

    You are really awesome dude

  • @Sarojkumar-yh9uy
    @Sarojkumar-yh9uy 6 років тому +1

    awsome sir

  • @feisuxiaozhu
    @feisuxiaozhu 5 років тому

    very clear, thanks a lot!

  • @mahipalsingh-yo4jt
    @mahipalsingh-yo4jt 4 роки тому +1

    return "very well explained" ;

  • @jeeveshkataria6439
    @jeeveshkataria6439 4 роки тому +3

    wrong, Not work for skew trees

  • @DeepakGupta-zz1vf
    @DeepakGupta-zz1vf 3 роки тому

    Sir there are many videos which are not added in playlist, Can you please add it

  • @ganeshiitr-cse6328
    @ganeshiitr-cse6328 5 років тому

    Thanks ....

  • @PradeepSingh-ov3bt
    @PradeepSingh-ov3bt 6 років тому

    the error lies using 2 "if" instead of 1 if and 1 else if

  • @aayush5474
    @aayush5474 4 роки тому

    you need an extra condition to check if the tree is skewed otherwise the code will fail

  • @vash721
    @vash721 6 років тому

    Sir can you plz explain the M-way search tree ........

  • @aashutoshvatsa5152
    @aashutoshvatsa5152 5 років тому

    can u please provide quick sorting and merge sorting .

  • @deepakgoyal589
    @deepakgoyal589 6 років тому

    Sir can u explain rope data structure please

  • @railgang5026
    @railgang5026 5 років тому

    Plz solve postorder traversal from
    Given in order,preorder

  • @user-mo1vm2nt7l
    @user-mo1vm2nt7l 5 років тому

    Sir your code is wrong it does not work for input (15,10,8,12,13,20,17,25)

  • @285ravi
    @285ravi 6 років тому

    its not printing in correct order, to get correct order,in right view all the printing statements should be just below of recursive calling function.

  • @vikasbajpai3013
    @vikasbajpai3013 6 років тому +3

    wrong code

  • @user-zj9pq5xc7x
    @user-zj9pq5xc7x 2 місяці тому

    you could have easily gone anticlockwise...this doesn't make much sense, sorry