It is recommended to refer following post as prerequisite of this post.
Following are the different cases to delete a key k from splay tree.
- If Root is NULL: We simply return the root.
- Else Splay the given key k. If k is present, then it becomes the new root. If not present, then last accessed leaf node becomes the new root.
- If new root’s key is not same as k, then return the root as k is not present.
- Else the key k is present.
- Split the tree into two trees Tree1 = root’s left subtree and Tree2 = root’s right subtree and delete the root node.
- Let the root’s of Tree1 and Tree2 be Root1 and Root2 respectively.
- If Root1 is NULL: Return Root2.
- Else, Splay the maximum node (node having the maximum value) of Tree1.
- After the Splay procedure, make Root2 as the right child of Root1 and return Root1.
Preorder traversal of the modified Splay tree is 2 1 6 9 7
This article is contributed by Ayush Jauhari. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Splay Tree | Set 1 (Search)
- Splay Tree | Set 2 (Insert)
- Red-Black Tree | Set 3 (Delete)
- K Dimensional Tree | Set 3 (Delete)
- Write a program to Delete a Tree
- Delete Operation in B-Tree
- Non-recursive program to delete an entire binary tree
- Deleting a binary tree using the delete keyword
- Delete the last leaf node in a Binary Tree
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Convert a Generic Tree(N-array Tree) to Binary Tree
- Treap | Set 2 (Implementation of Search, Insert and Delete)
- Efficiently design Insert, Delete and Median queries on a set
- Implementation of Binomial Heap | Set - 2 (delete() and decreseKey())
- Check if a binary tree is subtree of another binary tree | Set 1
- Check if a binary tree is subtree of another binary tree | Set 2
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
Improved By : nidhi_biet