Happy to report that I completed the prepend function prior to un-pausing the video. This is a huge win for me and couldn't have done it without your singly linked lists and circular linked list videos. It's starting to click!
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
I have watched manny video's on linked list but never understood that concept completely. But after watching this video I understood the concept clearly and now my confidence is also booted and now I am not at all afraid of linked lists. Thank you so much
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@@LucidProgramming yup..I did subscribed your channel when i saw your explanation..and yes on every video i gave a like.. your tutorial are so detailed to understand, even a noob can understand easily.... I was having manny doubts about linked list but after watching your tutorials all doubts were cleared. Thank you once again
I am trying to write programs before watching your videos and guess what?! I am totally able to! Thanks to your wonderful explanations of Singly Linked Lists, the picture has gotten perfectly clear in my head! God bless you man!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Thank you, Megan! :) I'm really happy to hear that this video was helpful to you. Indeed, that always makes my day to hear! Best of luck in your learning of data structures and happy coding! :)
Really appreciate that. I'm very happy to hear that you're gaining something from these videos. I do look forward to making more of these in the future, and best of luck on your programming journey! Cheers.
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Honestly, i liked the way you used ppt as well as python editor. Great Explanation Sir. I,m Expecting many examples like circular, Dfs, Bfs, A*, Greedy, Tree Traversing, Graphs. Thank you once again.
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
Thanks! perfect as usual. I have a little suggestion, I think that we don't need to assign new_node.next and new_node.prev to None in append() since they both are initialized to None in the Node class.
you are simply awesome. I was looking for some good video tutorial where i can revise DS using python and seems you are boon. I wonder how i stumble upon your lectures. you deserve more views !
Thank you for the great video series, I'm really enjoying them as a refresher. I get that you can just use a variable and update its value on every iteration (like you did for example with append(self, data) or print_list(self) functions, but the problem is that you are creating a new object in memory with every iteration (imagine you have a file with millions of data in that doubly linked list file, so it's not memory efficient). and that's what you did in your class based solution too (you used "cur = self.head" and then you used while loop to update "cur" variable with every iteration (small file is fine, but a big file would require you a lot of extra unnecessary memory). My solution I came up with today is to use a recursive loop (which doesn't create any extra objects in memory), as it only takes input (update "node = node[1]" and returns value if condition is True). x = [1, [2, [3, None]]] # This is a simple doubly linked list def print_list(x): print(x[0]) if x[1] is None: pass else: return print_list(x[1]) print_list(x) # 1 # 2 # 3 So basically, you just print the first element (data) and then you return by calling the function again but passing in the new value of "doubly[1]" list to be its 2nd element recursively. recursive solution is memory saver and efficient and just best practice in this situation in my opinion (memory saver, simple, and just clean). Your thoughts?
Hi Fouad. I'm not sure how you can construct a doubly linked list without treating the nodes as explicit objects and allocating memory for each of those nodes. Or perhaps I'm just misunderstanding the question that you're asking.
@@LucidProgramming oh no no, I think you got me wrong. When you first create the doubly linked list you definitely have to treat nodes as objects (as temporary variables). So, I'm not talking about when you first create the doubly list. I'm actually talking about the functions such as "append()", "prepend()", "print()", ...etc. I saw that all solutions on the internet (even on stackoverflow . com) they all use temporary variables with every iteration when traversing the nodes of the doubly list. But why use traditional iteration if you can use a better way? like using a recursive function (But keep in mind I'm applying Functional programming, not object oriented programming). For instance, in the case of the "print()" function, all you need is to pass to it the doubly list as an input, print the first node in it (read line 2 in my code above), then to go to the 2nd node, you don't have to use a temporary variable to go to 2nd node, instead, you can just call the same function "print()" within the function its self but this time pass the doubly list at position 1 (read line 11 in my code above). If you just copy and paste my code above as your "print()" function and test it, it will work fine. Test it as it is. Or use it in your code but pass "self" as input. The bottom line is that recursive functions don't need to use memory space with every iteration for them to work. thus you save memory as opposed to using variable and update it with every iteration requiring a new memory address with every iteration (as a new object is created with every iteration that the variable points to).
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
Thanks! I like that idea. If you check out my Patreon page that I just launched, you can make these types of suggestions there. Thanks for watching! :)
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
By the way everyone, if you want to have a "smoother" implementation of displaying all the values, you can do something like this: by declaring this magic method in class Node: def __repr__(self): if self.next is None: return f'{self.data}' return f'{self.data} -> {self.next}' and then declaring this magic method in class DoublyLinkedList: def __repr__(self): return f'{self.head}' you can use print(dllist) to display all of the elements in a nice little format.
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Enjoying your videoes! Sharing my way of implementing insert_after() method: def insert_after(self,ref_data,data): new_node = Node(data) if not self.head: print('Empty list-reference node invalid!') return cur = self.head while cur: if cur.data == ref_data: new_node.previous = cur new_node.next = cur.next if cur.next: #last node has no cur.next cur.next.previous = new_node cur.next = new_node return cur = cur.next print('reference node not found in list') return
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support, and if you want to support the channel, I do have a PayPal link paypal.me/VincentRusso1 for donations that go directly to the creation of content on this channel. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Great to hear that, RB! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page. bit.ly/lp_email
@lucidprogramming wish you could complete the remaining ds series and get on with problem solving too Enjoying learning coding from your channel You're the best
Thanks a lot sir but since you initially assigned the next and prev values to none in __init__method is it must for u again to do the same in the prepend and append methods.
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Keeping track of a tail pointer would improve the efficiency of the append and other methods to O(1), which is the main reason why we are riddling our selfs with all this code instead of using a plain list, right? Thank you very much for your work!
Hi Vincent, do you think you will add Graph Algorithms. I searched everywhere for tutorial as good as yours but couldn't find. Graph algorithms are really important and I wish if you could add those videos in your Data Structures playlist.
Hi Naveen. I'm thrilled to hear that this video was helpful for you. I also appreciate you mentioning that the link in the description is broken. Indeed, I've gone ahead and updated the link. Thank you very much for pointing that out! Cheers, and thanks again for watching.
Hi @LucidProgramming. The time complexity of the append function is O(n) and that of prepend is O(1) according to your code. Can you suggest improving the append function from O(n) to O(1) using a tail pointer?
Thank you for the videos. They are really helpful. I have a question about the prepend method. For the first case, is it ok if we do not say "new_node.prev = None" like bellow: (I mean in the Node class we have already told that node.prev is none.) def prepend(self, data): if self.head is None: new_node = Node(data) self.head = new_node
Hi Sara. Thanks for that comment, I'm glad the videos have proved useful to you. Regarding your question, you may not need that line as it's done in the constructor beforehand. At worst, that line would be redundant from looking at this again. Unless I'm missing some edge case, I believe you can remove it. Thanks for the question!
Then what about link bw them in reverse bcs previous head also will have current.next memory location just like reversed linked list and u dint use while loop to do it
hey lucid thanks a lot for the tutorial man, i have a small doubt- in the prepend block instead of new_node.prev=none, shouldn't be self .head.prev=none? coz we assigned new node to self.head right?
Hi Venkatesh. Thanks for the comment. Have you tried making this change? If so, have you noticed any behavior that is unexpected? My suggestion would be to figure out why that won't work, and then go from there. Hope that helps, and thanks for your comment!
First of all there is no need to set new_node.prev or new_node.next to None in any of these append and prepend methods, coz we have already initialised them in Node class __init__.
Hi @LucidProgramming Thank you very much for the time and effort you're putting here. I only have one question: I'm implementing the same as your custom functions here (for a project), but not using classes. I know how to traverse a double linked list using classes (I knowt the "self. next" should do it), but I couldn't find anyway to traverse the doubly linked list without without using classes. I want to traverse it without modifying it (just like when using classes we only need to use self. next of the defined Node class). In other words: I want to traverse it and then do whatever I want BUT in place (append or add or delete or reverse, ...etc but in place), without creating another list, without using classes. Any idea?
Hi Fouad. No problem, I'm glad you found the video to be useful. Regarding your question. I think I understand. You essentially want to implement this without using classes? Sure, that's possible. Classes are just a nice way to organize concepts that happen to have similar traits or properties. There's nothing specific about the use of classes that makes solving this problem proprietary. You should just be able to replace any of the usages of the class with some variables and that should do the trick. Hope that makes sense. Cheers.
@@LucidProgramming yup I understand, and I really appreciate it, but you are using a variable that creates a new object in memory with every iteration (think in case you have millions of data). not memory efficient solution. but works with small files/data
@@LucidProgramming I think the reason why you couldn't get my point is because I used functional and procedural programming in my code while you used object oriented programming.
@@LazerScalper Hi Fouad. Hmm, I'm not sure if that's the reason. I could be missing something, but I'm not sure that the reason for that is because the paradigm you are using is functional while the paradigm I'm using is object oriented. The issue seems to be a question as to whether or not an object is instantiated in memory or not, but I don't think the paradigm is the problem for our misunderstanding. Unless, perhaps I'm missing something.
@@LucidProgramming thanks man , your dsa course content is very good any idea for making new playlist for interviews like design round or leetcode problems ?
insert_before() method: def insert_before(self,ref_data,data): new_node = Node(data) if not self.head: print('Empty list-reference node invalid!') return cur = self.head while cur: if cur.data == ref_data: if cur.previous is None: self.head = new_node else: cur.previous.next = new_node cur.previous = new_node new_node.next = cur return cur = cur.next print('reference node not found in list') return
@@njoy2075 Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. I hope to be putting out more similar videos soon!
I am little confused about something. The Node() class already had self.prev set to None in the init function. Why do you have to set self.prev to None again in the linked list append function in the loop (if self.head is None)? is the same task not already completed in the line new_node = Node(data) ????????????????
Some parts of it could probably be extracted, but you'll want to catch the two different conditions of when you're prepending to an empty list of a non-empty list.
Happy to report that I completed the prepend function prior to un-pausing the video. This is a huge win for me and couldn't have done it without your singly linked lists and circular linked list videos. It's starting to click!
Excellent! That's really great to hear. I'm loving hearing about your progress here, and I'm glad the content is starting to click. Cheers!
Your playlists about single, double and circular linked lists are great. It really helped me. Thank you for your contribution. Cheers :)
Best video on Doubly lists after watching top videos in TH-cam. Well explained! Thanks!
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
I have watched manny video's on linked list but never understood that concept completely. But after watching this video I understood the concept clearly and now my confidence is also booted and now I am not at all afraid of linked lists. Thank you so much
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@@LucidProgramming yup..I did subscribed your channel when i saw your explanation..and yes on every video i gave a like.. your tutorial are so detailed to understand, even a noob can understand easily.... I was having manny doubts about linked list but after watching your tutorials all doubts were cleared. Thank you once again
@@hackytech7494 That's great to hear, I'm really happy to hear that! Thank you again for the kind words!
I am trying to write programs before watching your videos and guess what?! I am totally able to! Thanks to your wonderful explanations of Singly Linked Lists, the picture has gotten perfectly clear in my head! God bless you man!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Really helpful! First time doing doubly linked lists and I was able to follow exactly what you did and why. Thank you!
Thank you, Megan! :) I'm really happy to hear that this video was helpful to you. Indeed, that always makes my day to hear! Best of luck in your learning of data structures and happy coding! :)
You do a very good job of explaining to someone who has never done programming before (like me) and I thank you for it. Keep up the good work!
Really appreciate that. I'm very happy to hear that you're gaining something from these videos. I do look forward to making more of these in the future, and best of luck on your programming journey! Cheers.
awesome , waiting for you to add more to this series.. it seriously deserves at least a million views, not even kidding
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
@@LucidProgrammingsure, waiting for them eagerly!!
@@pythonenthusiast9292 Thanks! Really looking forward to getting to producing them. Cheers!
Explained perfectly, 90% of my problems with dLL ceased.
That's great to hear Muhammed. Thanks for your comment, and again, I'm thrilled to hear that! Cheers.
really helpful. the way you explained using diagram, helped me to code myself. Thank you very much.
Cheers, and thanks for watching!
Honestly, i liked the way you used ppt as well as python editor. Great Explanation Sir. I,m Expecting many examples like circular, Dfs, Bfs, A*, Greedy, Tree Traversing, Graphs. Thank you once again.
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
I really appreciate the support, and if you want to support the channel, I do have a PayPal link (www.paypal.me/VincentRusso1) for donations that go directly to the creation of content on this channel.
I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
Thanks! perfect as usual.
I have a little suggestion, I think that we don't need to assign new_node.next and new_node.prev to None in append() since they both are initialized to None in the Node class.
Thanks, and yes, I do appreciate the input! Thanks again! :)
The Explanation is a good. Also you can new_node = Node(data) can be assigned only one time .
you are simply awesome. I was looking for some good video tutorial where i can revise DS using python and seems you are boon. I wonder how i stumble upon your lectures. you deserve more views !
Thanks, and if you think that, please do share this content with others who you think might benefit from it as well! Cheers, and thanks for watching.
Thank you sir, your code is simple and easy to understand and your explanation techniques is also very good. Subscribed the channel!
Really appreciate that, and thank you for the support!
Thank you for the great video series, I'm really enjoying them as a refresher.
I get that you can just use a variable and update its value on every iteration (like you did for example with append(self, data) or print_list(self) functions, but the problem is that you are creating a new object in memory with every iteration (imagine you have a file with millions of data in that doubly linked list file, so it's not memory efficient). and that's what you did in your class based solution too (you used "cur = self.head" and then you used while loop to update "cur" variable with every iteration (small file is fine, but a big file would require you a lot of extra unnecessary memory).
My solution I came up with today is to use a recursive loop (which doesn't create any extra objects in memory), as it only takes input (update "node = node[1]" and returns value if condition is True).
x = [1, [2, [3, None]]] # This is a simple doubly linked list
def print_list(x):
print(x[0])
if x[1] is None:
pass
else:
return print_list(x[1])
print_list(x)
# 1
# 2
# 3
So basically, you just print the first element (data) and then you return by calling the function again but passing in the new value of "doubly[1]" list to be its 2nd element recursively.
recursive solution is memory saver and efficient and just best practice in this situation in my opinion (memory saver, simple, and just clean).
Your thoughts?
Hi Fouad. I'm not sure how you can construct a doubly linked list without treating the nodes as explicit objects and allocating memory for each of those nodes. Or perhaps I'm just misunderstanding the question that you're asking.
@@LucidProgramming oh no no, I think you got me wrong. When you first create the doubly linked list you definitely have to treat nodes as objects (as temporary variables).
So, I'm not talking about when you first create the doubly list. I'm actually talking about the functions such as "append()", "prepend()", "print()", ...etc.
I saw that all solutions on the internet (even on stackoverflow . com) they all use temporary variables with every iteration when traversing the nodes of the doubly list.
But why use traditional iteration if you can use a better way? like using a recursive function (But keep in mind I'm applying Functional programming, not object oriented programming).
For instance, in the case of the "print()" function, all you need is to pass to it the doubly list as an input, print the first node in it (read line 2 in my code above), then to go to the 2nd node, you don't have to use a temporary variable to go to 2nd node, instead, you can just call the same function "print()" within the function its self but this time pass the doubly list at position 1 (read line 11 in my code above).
If you just copy and paste my code above as your "print()" function and test it, it will work fine. Test it as it is. Or use it in your code but pass "self" as input.
The bottom line is that recursive functions don't need to use memory space with every iteration for them to work. thus you save memory as opposed to using variable and update it with every iteration requiring a new memory address with every iteration (as a new object is created with every iteration that the variable points to).
@@LazerScalper i think when everyone does it one way and u do it the other, ur the wrong one? not attacking, just an honest comment
Amazing video, thank you for the knowledge!!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
OMG, really good video! really good! I just solve my algorithm assignment, thank you!!!!
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
You have helped me a lot. Thank you for the tutorial
Brilliant explanation, thanks a lot
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
I really appreciate the support, and if you want to support the channel, I do have a PayPal link
paypal.me/VincentRusso1
for donations that go directly to the creation of content on this channel.
I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
Could you make some series about code optimization? I love your videos. Very helpful during studies, a great source of knowledge!
Thanks! I like that idea. If you check out my Patreon page that I just launched, you can make these types of suggestions there. Thanks for watching! :)
you save me.. thank you!! such a good tutorial!!
Glad to hear it, thanks for watching!
Your videos are very helpful. Thank you.
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
By the way everyone, if you want to have a "smoother" implementation of displaying all the values, you can do something like this:
by declaring this magic method in class Node:
def __repr__(self):
if self.next is None:
return f'{self.data}'
return f'{self.data} -> {self.next}'
and then declaring this magic method in class DoublyLinkedList:
def __repr__(self):
return f'{self.head}'
you can use print(dllist) to display all of the elements in a nice little format.
Cool, thanks for sharing that we everyone!
Thank you sir......It is really very helpful ❣❣❣❣❣❣❣❣❣❣❣❣❣
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Man you're a plus
Appreciate that! :)
Enjoying your videoes!
Sharing my way of implementing insert_after() method:
def insert_after(self,ref_data,data):
new_node = Node(data)
if not self.head:
print('Empty list-reference node invalid!')
return
cur = self.head
while cur:
if cur.data == ref_data:
new_node.previous = cur
new_node.next = cur.next
if cur.next: #last node has no cur.next
cur.next.previous = new_node
cur.next = new_node
return
cur = cur.next
print('reference node not found in list')
return
great work keep it up appreciated.
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing!
I really appreciate the support, and if you want to support the channel, I do have a PayPal link
paypal.me/VincentRusso1
for donations that go directly to the creation of content on this channel.
I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
Lovely explanation!
Thank you! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
@@LucidProgramming done!
@@PranayZVlogs Thank you! :)
great and quality content
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Great video
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Thanks, very clear explanations :)
Great to hear that, RB! If you like my content, I've been working on some projects during the past couple of months. If you would like to stay up-to-date, please consider subscribing to my mail list. Also, if you haven't already, please consider subscribing! I really appreciate the support. I hope that the content I provide there will enhance the videos on my TH-cam page.
bit.ly/lp_email
@lucidprogramming wish you could complete the remaining ds series and get on with problem solving too
Enjoying learning coding from your channel
You're the best
Been quite busy these days, but I sincerely appreciate your support!
Thank You
No problem, thanks for watching and for the comment! :)
Thank you dude
Thanks a lot sir but since you initially assigned the next and prev values to none in __init__method is it must for u again to do the same in the prepend and append methods.
Thanks you are great ^-^
Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. If you would like to support the content creation on this channel please consider unblocking ads when watching my videos as this is how I support my time to make content. I hope to be putting out more similar videos soon!
Keeping track of a tail pointer would improve the efficiency of the append and other methods to O(1), which is the main reason why we are riddling our selfs with all this code instead of using a plain list, right?
Thank you very much for your work!
We are mostly going through this to understand the notion of a linked list. Cheers!
nice stuff
Thanks! :)
thank you !
Hi Vincent, do you think you will add Graph Algorithms. I searched everywhere for tutorial as good as yours but couldn't find. Graph algorithms are really important and I wish if you could add those videos in your Data Structures playlist.
I caught the error of not updating (cur.next = new_node) before you. Yipeeeeeeeee
Haha, nice one :)
you made it cakewalk for me. Thanks and really helpful. BTW, github link is not working now. Do consider updating them.
Hi Naveen. I'm thrilled to hear that this video was helpful for you. I also appreciate you mentioning that the link in the description is broken. Indeed, I've gone ahead and updated the link. Thank you very much for pointing that out! Cheers, and thanks again for watching.
Hi @LucidProgramming. The time complexity of the append function is O(n) and that of prepend is O(1) according to your code. Can you suggest improving the append function from O(n) to O(1) using a tail pointer?
You definitely could do that if you wanted to. It's up to you if you want to take on the additional overhead of keeping track of the tail pointer.
Thank you for the videos. They are really helpful.
I have a question about the prepend method. For the first case, is it ok if we do not say "new_node.prev = None" like bellow: (I mean in the Node class we have already told that node.prev is none.)
def prepend(self, data):
if self.head is None:
new_node = Node(data)
self.head = new_node
Hi Sara. Thanks for that comment, I'm glad the videos have proved useful to you. Regarding your question, you may not need that line as it's done in the constructor beforehand. At worst, that line would be redundant from looking at this again. Unless I'm missing some edge case, I believe you can remove it. Thanks for the question!
@@LucidProgramming Thanks for the reply.
@@sarasalam1766 No problem, hope it helped!
thanks mem
Then what about link bw them in reverse bcs previous head also will have current.next memory location just like reversed linked list and u dint use while loop to do it
Can you make a video about sorting datas in doubly linked list?
That's definitely on my "to-do" list. Thanks for your suggestion!
hey lucid thanks a lot for the tutorial man, i have a small doubt- in the prepend block instead of new_node.prev=none, shouldn't be self .head.prev=none? coz we assigned new node to self.head right?
Hi Venkatesh. Thanks for the comment. Have you tried making this change? If so, have you noticed any behavior that is unexpected? My suggestion would be to figure out why that won't work, and then go from there. Hope that helps, and thanks for your comment!
First of all there is no need to set new_node.prev or new_node.next to None in any of these append and prepend methods, coz we have already initialised them in Node class __init__.
Hi @LucidProgramming
Thank you very much for the time and effort you're putting here. I only have one question: I'm implementing the same as your custom functions here (for a project), but not using classes. I know how to traverse a double linked list using classes (I knowt the "self. next" should do it), but I couldn't find anyway to traverse the doubly linked list without without using classes.
I want to traverse it without modifying it (just like when using classes we only need to use self. next of the defined Node class).
In other words: I want to traverse it and then do whatever I want BUT in place (append or add or delete or reverse, ...etc but in place), without creating another list, without using classes.
Any idea?
Hi Fouad. No problem, I'm glad you found the video to be useful.
Regarding your question. I think I understand. You essentially want to implement this without using classes? Sure, that's possible. Classes are just a nice way to organize concepts that happen to have similar traits or properties. There's nothing specific about the use of classes that makes solving this problem proprietary. You should just be able to replace any of the usages of the class with some variables and that should do the trick. Hope that makes sense. Cheers.
@@LucidProgramming yup I understand, and I really appreciate it, but you are using a variable that creates a new object in memory with every iteration (think in case you have millions of data). not memory efficient solution. but works with small files/data
@@LazerScalper Hi Fouad. What variable would you be referring to? I'm not exactly sure what part of the code you're mentioning here.
@@LucidProgramming I think the reason why you couldn't get my point is because I used functional and procedural programming in my code while you used object oriented programming.
@@LazerScalper Hi Fouad. Hmm, I'm not sure if that's the reason. I could be missing something, but I'm not sure that the reason for that is because the paradigm you are using is functional while the paradigm I'm using is object oriented. The issue seems to be a question as to whether or not an object is instantiated in memory or not, but I don't think the paradigm is the problem for our misunderstanding. Unless, perhaps I'm missing something.
i tried like this def append(self,data):
newNode = Node(data)
temp = self.tail
self.tail = newNode
self.tail.prev = temp.data
self.head.next = newNode.data
self.length += 1
Nice, thank you for sharing!
@@LucidProgramming thanks man , your dsa course content is very good any idea for making new playlist for interviews like design round or leetcode problems ?
@@gunahawk6893 Thank you very much! Honestly, if I am able to find the time, I would love to do something like that!
@@LucidProgramming thanks man have a nice day
insert_before() method:
def insert_before(self,ref_data,data):
new_node = Node(data)
if not self.head:
print('Empty list-reference node invalid!')
return
cur = self.head
while cur:
if cur.data == ref_data:
if cur.previous is None:
self.head = new_node
else:
cur.previous.next = new_node
cur.previous = new_node
new_node.next = cur
return
cur = cur.next
print('reference node not found in list')
return
Cool, thanks for sharing!
This prepend is basically assigning a new head .
Yes, exactly.
@@LucidProgramming This set of videos are really nice. Thank you for the content.
@@njoy2075 Cheers! If you enjoyed and benefited from my content, please consider liking the video and subscribing to the channel for more content like this. I hope to be putting out more similar videos soon!
hey, I just have a question about the if statement of append function, in what situation the self.head would be None? Thanks
We set it to None, so if nothing is put into the head, it would be None, for instance.
hello bro, I have seen many of your video tutorials, may I ask for the presentation to be used as my study material for this video.? thx u :)
Updated the description with a link to the slides. Cheers, and thanks for watching!
@@LucidProgramming oke thx you bro :)
@@projectaddictive5226 Np, enjoy!
I am little confused about something. The Node() class already had self.prev set to None in the init function. Why do you have to set self.prev to None again in the linked list append function in the loop (if self.head is None)? is the same task not already completed in the line
new_node = Node(data) ????????????????
Sure, in this case, that might be redundant. You could get rid of that line in this case if you wanted to.
why didnt you used tail pointer ..wiull be give us 0(1) time in append and prepend
Not sure I understand the comment.
@@LucidProgramming I mean you could use a tail pointer to point to the end node and deletion from end or insertion will be 0(1)
@@yashchauhan5710 Oh, sure, you could do that.
you did a lot of not needed code example in prepend u don't need that if statement
u could put the else block code direclty it will work
Some parts of it could probably be extracted, but you'll want to catch the two different conditions of when you're prepending to an empty list of a non-empty list.