Size of a Binary Tree | GeeksforGeeks

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

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

  • @santhoshcts5
    @santhoshcts5 7 лет назад +5

    for anyone thinking about iterative, just use a queue to add all the elements into it and finally return the size of the queue which is nothing but size of the tree . Again recursion is anyways o(n) complexity but sometimes interviewer may wants to check ur understanding by asking iterative way to write code - sunny

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

      That would add a space complexity of O(n) since Queue will at most have all the nodes in itself. I'm not sure, but the space complexity of this recursive approach is also O(n) since in the worst case, we may have a highly skewed tree with only left (or only right) children.

    • @ManviKumari-h1i
      @ManviKumari-h1i Год назад

      😊😊😊😊😊😊😊😊😊😊😊😊

  • @militarualexandru8189
    @militarualexandru8189 7 лет назад +2

    thank you man, this helped a lot ! I really was struggling this.

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

    one thing i would like to suggest is that u should make separate channels for data structure , mathematical programming and u should update your playlists time to time

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

    Is there any problem using any pre/post/in order traveling and at the point of printing the node add that node to the array at the end size of array is size of tree please suggest if I am doing any wrong here

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

    Thanks for this😀

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

    u are doing a great job

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

    can't you just do in order traverse and add to the count whenever a node is visited. i understand this works but this another algorithm to remember.

  • @tejasbavkar2811
    @tejasbavkar2811 2 года назад

    thank you, for video.

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

    nice