Join Raghavendra Dixit for an in-depth discussion in this video Deleting the head node, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] We have already seen…how to insert a node at the head of a link list.…Now let's see how we can delete…the head node from a link list.…Consider a link list as shown here.…The head node is to be deleted from the link list.…And how do we do that?…Give it a thought, it is very simple.…To delete the node at the head, all we need to do…is to make the head reference of a link list object…point to the next node of the head object.…
So, let's do that and see what happens.…As you can see, there is no reference to the previous head.…That is, no object reference points to it now.…It is to be noted here that,…although this node may be pointing to the next node,…but nothing points to it, and thus it is not connected…to the link list in any way…and is ready for garbage collection.…So it gets deleted.…This is how we delete the head node from a link list.…
Note that deleting a head node…is also a constant time operation.…That is, it takes order of one time.…Now, let's see how we can implement this.…Let's go to the link list class…
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.