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
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.
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
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
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
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.
😊😊😊😊😊😊😊😊😊😊😊😊
thank you man, this helped a lot ! I really was struggling this.
Thanks Militaru Alexandru. We're glad you found it useful.
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
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
Thanks for this😀
u are doing a great job
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.
thank you, for video.
nice