Discover a world of knowledge at Westonci.ca, where experts and enthusiasts come together to answer your questions. Join our Q&A platform to get precise answers from experts in diverse fields and enhance your understanding. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

Write a program that can take a tree as input and travers it in 3 different format (pre-order, in-order and post-order). Write a report, you can follow the attached file. You can modify the report as you want.

Sagot :

Answer:

Let us see different corner cases.

Complexity function T(n) — for all problem where tree traversal is involved — can be defined as:

T(n) = T(k) + T(n – k – 1) + c

Where k is the number of nodes on one side of root and n-k-1 on the other side.

Let’s do an analysis of boundary conditions

Case 1: Skewed tree (One of the subtrees is empty and other subtree is non-empty )

k is 0 in this case.

T(n) = T(0) + T(n-1) + c

T(n) = 2T(0) + T(n-2) + 2c

T(n) = 3T(0) + T(n-3) + 3c

T(n) = 4T(0) + T(n-4) + 4c