Please answer in JAVA code. Appreciated! For the following BST, 4 The Top View i
ID: 3711220 • Letter: P
Question
Please answer in JAVA code.
Appreciated!
For the following BST, 4 The Top View is: 1-2-5-6 As nodes 3 and 4 are under nodes 2 and 5 respectively, so those won't be visible from the top Hint: A node x is there in output if x is the topmost node at its horizontal distance Horizontal distance of left child of a node x is equal to horizontal distance of x minus 1, and that of right child is horizontal distance of x plus 1 Implement your own Binary Search Tree class. You have to insert the elements given in the input to a binary search tree to proceed Input Format: Take input from a file in1.txt. The first line contains the number of test cases T. For each test case the first line contains the number of nodes N and the next line contains N space separated integers Ai A2.. AN, where Ai denotes the data of the nodes in the order in which they are inserted in the Binary search tree Output Format: Print the data of the nodes from the top view of the binary search tree from left to right. Sample Input: 6 125364 Sample Output: 1-2-5-6Explanation / Answer
Hi Dear,
Please find my code. Question is too long.
Output:
Following are nodes in top view of Binary Tree
1 2 3 6
Process finished with exit code 0