# In a Binary Tree, can two nodes have the same value?

In a Binary Tree, can two nodes have the same value? For example:

     3
/ \
4   4
/ \
1   2


They are two different nodes, but they have the same value. Here is code:

function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}

const r = new TreeNode(3);
r.left = new TreeNode(4);
r.right = new TreeNode(4);
r.left.left = new TreeNode(1);

• A binary tree is just a tree where each node has at most two children. I’m assuming you’re referring to a binary search tree? Commented Mar 4, 2020 at 3:41

In Binary search trees, the order of nodes are as: $$leftnode. So, your code will always run into error if both left and right of a parent node is same.
• It is important to note that the ordering can be $left\leq parent < right$ or $left < parent \leq right$ Commented Mar 4, 2020 at 3:45
• Your first link is about Binary Search Tree. I think that's probably a special kind of binary tree. PDF files are hard to read and use. I think they're not appropriate for the web. I'm not sure if LeetCode is wrong or your are wrong, but leetcode has a lot of binary tree examples that don't match your leftnode < parentnode < rightnode rule. Commented Mar 4, 2020 at 3:58