Join Raghavendra Dixit for an in-depth discussion in this video Deleting an item: Soft delete, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] As you saw, the delete operation…is very complicated.…And to avoid this in practical use,…we use something called a soft delete.…And what we do is, when a node is to be deleted,…it is marked as deleted without actually deleting it.…But then, whenever we traverse the tree,…or search for an item, we need to make sure…that we don't consider those nodes which are…marked as deleted, all right?…So for that, we first create another field…inside the TreeNode class.…
Let's name it isDeleted,…and initialize it to false.…Then, let's write a method called delete on this TreeNode.…And, all this does is that it sets…the value of isDeleted to true.…And, let's write another public method…to read the value of isDeleted field, all right?…Then, let's go to the BinarySearchTree class,…and comment out this delete method.…
Let's rewrite the delete method.…And, here all we need to do…is to find the node with this data.…And, just mark it as deleted.…That's it.…And, in the find method of the TreeNode class,…we can just make this change…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.