Binary Tree/ Binary Search Tree
NickName:Mohit Gupta Ask DateTime:2016-09-09T00:26:43

Binary Tree/ Binary Search Tree

Can a Binary Tree / Binary Search Tree only have the parent and one of the left or right nodes?
Or is it mandatory to have both the left and right nodes?

Copyright Notice:Content Author:「Mohit Gupta」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39396043/binary-tree-binary-search-tree

Answers
OneCricketeer 2016-09-08T16:31:26

Binary implies two. Binary trees have two children pointers, not necessarily with references to anything. Parent references are not necessary - that is up to implementation. \n\nIf nodes were mandatory to have both children elements, then the tree would be infinite and leaves would not exist. \n\nSo, options for a node are \n\n\nleaf \nleft/right child only\nboth children\n\n\nOf course, there are alternative ways to think about a \"tree\". For example, take the binary heap array implementation. \n\n",


karastojko 2016-09-09T10:33:31

It is not mandatory, you can create other types of links if you want. Define up and down pointers like this.\n\nFor a node x define up pointer u(x) as:\n\n\nif x is the right child, then u(x) is the parent of x\nif x is left child or root, then u(x) is the lowest node on the right path of x\n\n\nFor a node x define down pointer d(x) as:\n\n\nif x's left subtree does not exist, then d(x) = x\nif left subtree exists, then d(x) points to the rightmost node of x's left subtree\n\n\nThis is so called ring representation of a tree.",


Saurav Sahu 2016-09-09T07:28:51

Actually, there is nothing mandatory other than just one rule (i.e. the maximum number of children that any binary tree node can have is two). \n\nTechnically:\n\nEven a NULL is considered as a tree node when we define TreeNode *root = NULL. \nThough, it has no practical significance, we do pass them as argument while calling insert, delete and display methods. \n\nSo, as a coder, assuming that a binary tree will always comprise of at least a parent node can prove fatal if the sanity of root is not checked before processing a binary tree. ",


More about “Binary Tree/ Binary Search Tree” related questions

Binary Tree, Binary Search Tree, Binary search

I am trying to understand the Binary tree and referring to online material , and questions asked in SO. I understood that: Binary tree -> Tree in which each node can have at most 2 nodes. Binary

Show Detail

Is this tree a binary search tree?

I am trying to solve a binary search tree problem, but I can't pass all of the test cases. I need to return true if the tree is a binary search tree, otherwise, I need to return false. I also need to

Show Detail

Binary Tree/ Binary Search Tree

Can a Binary Tree / Binary Search Tree only have the parent and one of the left or right nodes? Or is it mandatory to have both the left and right nodes?

Show Detail

Binary tree to Binary Search Tree (BST)

How can you convert Binary Tree to Binary Search Tree with O(1) extra space ?

Show Detail

convert a not-full binary search tree to full binary search tree

I have a trouble in full binary search tree How can I convert a a not-full binary search tree to full binary search tree, such as this example: I have a structure of Node in tree: struct Node { ...

Show Detail

Binary search vs binary search tree

What is the benefit of a binary search tree over a sorted array with binary search? Just with mathematical analysis I do not see a difference, so I assume there must be a difference in the low-level

Show Detail

Largest Binary Search Tree in a Binary Tree

So, the question is to find the largest sub-tree (the largest sub-tree is the node with maximum size) in a binary tree which is a BST. I found the following website which enlists an algorithm. ht...

Show Detail

Difference between binary tree and binary search tree

Can anyone please explain the difference between binary tree and binary search tree with an example?

Show Detail

What is the difference between a balanced binary search tree and a binary search tree?

Sorry if this is an extremely basic question, but I am fairly new to trees and hence, this doubt bothers me these days. What is the difference between a binary search tree and a balanced binary se...

Show Detail

Binary Search Tree a Sub-category of Binary Tree?

I was asked the following question on an exam: What is the name of this data structure (algorithm used to fill the data structure, as covered by the textbook)? I answered that it was a binary...

Show Detail