Different Node Deletion/Insertion in a Binary Search Tree

AI Thread Summary
The discussion centers on the implications of using a pointer to a node's successor instead of its parent in a binary search tree. While searching remains unchanged, insertion and deletion processes would require adjustments to accommodate the need for finding both the successor and predecessor of nodes. The proposed pseudocode for finding the predecessor demonstrates that this operation could take O(n) time, as it involves traversing the tree to locate the least element and then finding the desired node's predecessor. This raises concerns about the efficiency of insertion and deletion, which would theoretically take at least Ω(n) time, contradicting established expectations of O(h) time as noted in Cormen's textbook. However, further discussion reveals that the predecessor method can be optimized to O(h), allowing both insertion and deletion to also operate within O(h) time. The conversation references Knuth's work and other algorithm resources, indicating that the topic is well-covered in literature.
mooncrater
Messages
215
Reaction score
18
What happens, if instead of having any pointer pointing to a node's parent, we had pointer pointing to the node's successor? We know, that Searching would remain the same. But in my opinion Insertion and Deletion would change. This would happen, because in insertion, we would be needed to find the successor and predecessor of the inserted node, and changing information accordingly. And in Deletion, we would be needed to re-align the successor value of the predecessor of the deleted element.
This shows the dependency of both the modified methods on finding the predecessor of the inserted/deleted element. My pseudocode for finding the predecessor is:
Code:
Predecessor(T,x)
1. y= T.root
2. while y.left_child ! = NULL
3.            y = y.left_child
4. while y.succ ! = x
5.           y = y.succ
6.return y
Here, lines 2-3 find the least element of the tree, and lines 4-5 find the element whose successor is ##x##(where ##x## is the pointer to the desired node.)
As we can see, that lines 4-5 take ##O(n)## time, (where ##n## is the total number of elements) instead of ##O(h)## time.(where ##h## is the height of the tree) .
This being said, leads to a conclusion that both the methods INSERT and DELETE would take atleast ##\Omega (n)## time. But according to a question in cormen(12.3-5) [https://github.com/yaoshengzhe/notes/blob/master/clrs/12_binary_search_trees.md] , it should be ##O(h)##.
So where am I wrong?
Any help is appreciated with a lot of thankfulness. :P
Moon.
 
Last edited by a moderator:
Technology news on Phys.org
Doesn't Knuth. Volume 3, discuss this?
 
  • Like
Likes mooncrater
The github link didn't work for me, but the description sounds like a 'threaded binary search tree'.
 
  • Like
Likes mooncrater
@anorlunda - Yup - Knuth does cover that. So does Cormen, so does Sedgewick in Algorithms in C Parts 1 - 4. All of which are wonderful resources!
 
  • Like
Likes mooncrater
Thanks for you people replying out there. I just got the answer, and well, it's simple ( and a little embarrassing too!). My predecessor method isn't optimal. It can be made in ##O(h)##. So We can get INSERT and DELETE to work in ##O(h)##.
Thanks.
Moon.
 
1477394289968.jpg

This might suffice.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top