Question: Given a pointer to the root of a binary tree, print the top view of the binary tree. The tree as seen from the top

Given a pointer to the root of a binary tree, print the top view of the binary tree.
The tree as seen from the top the nodes, is called the top view of the tree.
For example :
\table[[1,],[1,],[2,],[1,],[5,],[11,1],[36,6],[1,],[4,]]
Top View : 1256
Complete the function topView and print the resulting values on a single line separated by space.
Input Format
You are given a function,
void topView(node ** root){
}
Constraints
1 Nodes in the tree 500
Output Format
Print the values on a single line separated by space.
Sample Input
\table[[1],[1,],[2,],[1,],[5,],[11,1],[36,6],[1,],[4,]]
Sample Output
1256
Explanation
\table[[1],[1,],[2,],[1,],[5,],[11,1],[36,6],[1,],[4,]]
From the top, only nodes 1,2,5,6 are visible. We are given this code to work with:
import java.util.;
class Node {
Node left;
Node right;
int data;
Node (int data){
this. data = data;
left = null;
right = null;
}
}
class Solution {
/*
class Node
int data;
Node left;
Node right;
**1
public static void topView(Node root){
}
public static Node insert(Node root, int data){
if (root == null
 Given a pointer to the root of a binary tree, print

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!