Vertical Sum of a Binary Tree. (Column-Wise Sum)

Hello everybody, I was solving a Data-Structure Problem , Finding the Vertical Sum in a binary tree.

Vertical Sum means sum of nodes in same column.

Let me explore the question with an example.

Examples:

      1
    /   \
  2      3
 / \    / \
4   5  6   7

The tree has 5 vertical lines

Vertical-Line-1 has only one node 4 => vertical sum is 4

Vertical-Line-2: has only one node 2=> vertical sum is 2

Vertical-Line-3: has three nodes: 1,5,6 => vertical sum is 1+5+6 = 12

Vertical-Line-4: has only one node 3 => vertical sum is 3

Vertical-Line-5: has only one node 7 => vertical sum is 7

We can find this problem here [link][1] also on @geeksforgeeks.

I got the concept of Horizontal Distance.

My problem is how to implement Hash Map in C++ ??

In that we have keys with -ve values.

Please any-body explain how to implement Hash-Map in C++ .

Thanks and Happy Coding!!!
[1]: http://www.geeksforgeeks.org/vertical-sum-in-a-given-binary-tree/

2 Likes

No-Body here to answer…

1 Like
//