We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Index 1 and the value of the root are not the same. Binary tree root can contain any value. That part of the problem declaration is ambiguous. For example:

5/ \
32/\/ \
106917

Is still a binary tree. It's not sorted, but that does not disqualify it as a binary tree.

The problem says "You are given a tree of n nodes where nodes are indexed from 1..n and it is rooted at 1. " So we can safely assume that the binary tree we will be given for this problem always has a root of 1. I dealt with this by creating a BinaryTree object with a root of 1.

## Swap Nodes [Algo]

You are viewing a single comment's thread. Return to all comments →

Index 1 and the value of the root are not the same. Binary tree root can contain any value. That part of the problem declaration is ambiguous. For example:

Is still a binary tree. It's not sorted, but that does not disqualify it as a binary tree.

The problem says "You are given a tree of n nodes where nodes are indexed from 1..n and it is rooted at 1. " So we can safely assume that the binary tree we will be given for this problem always has a root of 1. I dealt with this by creating a BinaryTree object with a root of 1.

What does rooted at 1 mean ? It is ambiguous. Rooted at index 1 or the root element is 1 ?