can a node be inserted at a non leaf position in a binary search tree?
can a node be inserted in a non leaf position in a binary search tree ?
for eg. if we have the following set of numbers to be arranged as a binary serach tree :-
20.,17,15,19,23,25....
so there is more than 1 way these numbers can be arranged as a bst :-
20 17 23 15 19 25
20开发者_C百科 15 23 17 25 19
25 make it a root and place the other nodes accordingly....
I think you could devise some way to do that. But the normal algorithm for inserting into a BST doesn't do it and I don't see any reason why would you want to do that. Also, I don't know about any other publicly known algorithm that does that.
A binary search tree is just a tree with certain properties. You can use different algorithms for inserting nodes into such a tree, as long as these algorithms ensure that the properties required for a BST hold. So, yes, you can add nodes in other places than leafes if you want to.
精彩评论