Different Node Deletion/Insertion in a Binary Search Tree

Click For Summary

Discussion Overview

The discussion revolves around the implications of modifying a binary search tree (BST) by using a pointer to a node's successor instead of a pointer to its parent. Participants explore how this change affects insertion and deletion operations, particularly in terms of time complexity and the methods for finding predecessors.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests that using a pointer to a node's successor would complicate insertion and deletion operations, requiring additional steps to find predecessors and successors.
  • The proposed pseudocode for finding the predecessor is critiqued for its time complexity, which the participant initially claims to be O(n) instead of O(h).
  • Another participant references Knuth's Volume 3 as a source that discusses related concepts.
  • A different participant mentions that the described structure resembles a 'threaded binary search tree'.
  • Further replies confirm that Knuth, Cormen, and Sedgewick cover similar topics, suggesting that these resources may provide additional insights.
  • The original poster later acknowledges that their predecessor method can be optimized to O(h), allowing insertion and deletion to also operate in O(h) time.

Areas of Agreement / Disagreement

There is no clear consensus on the implications of using a successor pointer, as participants discuss various aspects and resources without resolving the initial concerns about time complexity.

Contextual Notes

The discussion includes assumptions about the structure and properties of binary search trees, as well as the efficiency of different methods for finding predecessors. The initial claims about time complexity are not fully resolved, and the implications of the proposed changes remain under debate.

Who May Find This Useful

Readers interested in data structures, particularly binary search trees, and those exploring algorithm optimization may find this discussion relevant.

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   Reactions: mooncrater
The github link didn't work for me, but the description sounds like a 'threaded binary search tree'.
 
  • Like
Likes   Reactions: 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   Reactions: 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.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
22K
  • · Replies 2 ·
Replies
2
Views
2K