New answers tagged

7

Is it possible to do a binary search tree if the data does not possess natural ordering? I don't know what the word "natural" means in your context; it seems vague. Moreover, images, videos, executables and sound files all seem perfectly obviously orderable to me. Order them by byte ordinal comparison, in the event of a tie, the shorter file is ...


3

An order is just a relationship between two elements in a set. The relationship is not always "is greater than". For example the relationship "is the son of" is, mathematically speaking, an order. It is not the order you need for a binary search because it is not well defined for all the elements: what if I pick two siblings? This relation exist only for ...


2

There's orderable data (which may be unordered), but it can be sorted by a variety of sorting algorithms. All of these sorting algorithms depend on the ability to perform a basic comparison ordering test between arbitrary given elements. Such a comparison must return the relative ordering of any two of the elements, for example, usually as -1 for less, 0 ...


1

From what i know there is no way like you mentioned to hook the vertex to some node. what you can do is to take the elements from smaller tree and insert them into the larger one.(Long method) Or You can do inorder traversal of 1st tree store it in array1 takes O(n) time. Apply same for 2nd tree and store in array2 O(n) time. These 2 arrays would be ...


1

If you don't care about using extra memory then you can dump out the BST into a sorted array. Then you can balance the new tree perfectly. tree balance(int[] array){ if(array.length == 0) return null; Node n = new Node(array[$/2]); n.left = balance(array[0..$/2]); n.right = balance(array[$/2+1..$]); return n; } This still needs to ...



Top 50 recent answers are included