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.

Respuesta :

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