Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Nodes in Binary Tree Columns (Main Thread)

Here is the interview question prompt, presented for reference.

Vertical Order Traversal of a Binary Tree

What is Vertical Order Traversal?

In a binary tree, each node has a position defined by its (row, col) coordinates. The vertical order traversal is a method of visiting all the nodes in the tree column-by-column, starting from the leftmost to the rightmost columns. In this traversal, for each column, you will go from the top node to the bottom node.

Imagine the tree as a grid. The root node sits at (0, 0) and as you move down the tree, the row number increases. When you go left, the column number decreases, and when you go right, the column number increases.

![image](https://storage.googleapis.com/algodailyrandomassets/curriculum/binary-search-trees/nodes-binary-tree-columns/problem.png)

Sorting Nodes in the Same Column

Sometimes, you'll find multiple nodes in the same row and column. When this happens, you should sort these nodes based on their values, in ascending order.

Coordinates of Child Nodes

For any node at (row, col), its children will be positioned as follows: - The left child will be at (row + 1, col - 1) - The right child will be at (row + 1, col + 1)

Constraints

  • The tree will have between 1 and 1000 nodes.
  • The value of each node will be in the range [0, 1000]

You can see the full challenge with visuals at this link.

Challenges • Asked about 2 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Dec 16, 2022:

This is the main discussion thread generated for Nodes in Binary Tree Columns (Main Thread).