Suppose a binary tree stores integers write efficient


Question: Suppose a binary tree stores integers. Write efficient methods (and give their Big-Oh running times) that take a reference to a binary tree root T and compute

a. The number of even data items

b. The sum of all the items in the tree

1 public static void mysteryPrint( BinaryNode t )

2 {

3     if( t != null )

4       {

5             System.out.println( t.getElement( ) );

6             mysteryPrint( t. getElement( ) );

7             System.out.println( t.getElement( ) );

8             mysteryPrint( t. getRight( ) );

9             System.out.println( t.getElement( ) );

10       }

11 }

c. The number of nodes with two children that contain the same value

d. The length of the longest strictly increasing sequence of numbers that follow a path down the tree. The path does not have to include the root.

e. The length of the longest strictly increasing sequence of numbers that follow a path down the tree. The path must include the root.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Suppose a binary tree stores integers write efficient
Reference No:- TGS02462621

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)