![]() |
Let us discuss the Time and Space complexity of different Tree Traversal techniques, such as Inorder Traversal, Preorder Traversal, Postorder Traversal, etc. Time Complexity of Tree Traversal AlgorithmsLet us see different corner cases: Complexity function T(n) — for all problems where tree traversal is involved — can be defined as:
Let’s do an analysis of boundary conditions:
Auxiliary Space of Tree Traversal AlgorithmsO(1) If we don’t consider the size of the stack for function calls then O(1) otherwise O(h) where h is the height of the tree. Note: The height of the skewed tree is n (no. of elements) so the worst space complexity is O(N) and the height is (log N) for the balanced tree so the best space complexity is O(log N). |
Reffered: https://www.geeksforgeeks.org
DSA |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |