Arunvijay28 / Java-Programs

0 stars 14 forks source link

Implemented Boundary Traversal in Binary Tree #21

Closed Heet-Patel-5304 closed 3 weeks ago

Heet-Patel-5304 commented 1 month ago

Description

Summary

This pull request introduces a Java implementation of a binary tree boundary traversal algorithm. The primary functionalities include traversing the left boundary, leaf nodes, and the right boundary of the binary tree, while ensuring that no node is traversed more than once. The solution is structured to handle both null nodes and trees with varying structures (complete, incomplete, etc.).

The main components of the algorithm are:

Testing Instructions

Test Case 1:

Input:

1
1 2 3 4 N 5 6 N N 7 8

Output:

1 2 4 7 8 6 3

This test case checks the traversal of a binary tree with mixed left and right children, validating the correctness of both boundary and leaf node traversal.

Test Case 2:

Input:

1
1 N 2 N 3 N 4 N 5

Output:

1 2 3 4 5

This tests a right-skewed tree, ensuring that the right boundary traversal is correctly handled.

Test Case 3:

Input:

1
1

Output:

1

This test checks the case of a tree with only a root node.

How to Run the Tests

1. Compile the program using:

javac Main.java

2. Run the program:

java Main

3. Provide the input as shown in the test cases. Each test case begins with an integer representing the number of test cases, followed by space-separated strings representing the tree's level-order traversal.

4. The output will be printed in the console.