I dont understand part 6:28. If we want to insert a new head. Shouldnt new_node.next = self.head , and self.head = new_node . So we first point the new head to the old head node, then we assign it as the new head. But now you are inserting a node between the old head and the old heads next node ... ?
we are not doing new_node.next = self.head because remember self.head is the dummy node before the actual head of the linked list. So to point the new node to the old head you have to do new_node.next = self.head.next( this gives the old head)
Well I hope my data structure college course would be helpful xD. But we did it using struct in c++ and not class but I guess the same idea could be applied here.
I really need your help on knowing where I can learn the fundamentals of understanding this code. Like, I know the syntax for Python and loops and all that but I don't know anything about classes or objects or even how you could do self.head.next at 4:10. Could you guide me on where I could learn those fundamentals? Any help is appreciated, thank you.
Learn about classes, superclass/parentclass and then subclass/childclass. Along with inheritance and polymorphism. 1 month late so maybe you already got your answer but if not there's lots of guides or ask chatgpt (what I did at least)
Depends on scenario but basically if you create a new node Self.head = new node Self.tail = self.head The second line means that they are both pointing to the new node You could also say self.tail = new node basically in this scenario its the "same"
when doing the get method in the single linked list, are we not counting head and tail when considering the index in the linked list as per your code if I pass 0 to the get function I will be getting the node value next to the head and not the head. @NeetCodeIO please do reply
He keeps the dummy head node and never removes/replaces it. I'm not sure why, it seems silly to keep this dummy node (or to even initialize with a dummy node in the first place). So yes, when creating your get method you should start the pointer at the self.head.next as he shows at 3:33 Personally, I think this entire design is flawed in keeping the dummy nodes that serve no real purpose. We should just be initializing an empty list, and if you go to insert a head or tail when there is no current head or tail, both are set to the new node or return some error stating there is no head/tail. Maintaining the dummy node just adds another variable to consider when making changes to the LinkedList that are unnecessary. Interviewers likely would appreciate seeing you handle edge cases such as this anyway.
Setting the head to an empty value really makes a huge difference
BRING BACK THE OLD THUMBNAIL
I dont understand part 6:28. If we want to insert a new head. Shouldnt new_node.next = self.head , and self.head = new_node . So we first point the new head to the old head node, then we assign it as the new head. But now you are inserting a node between the old head and the old heads next node ... ?
Yup. That was frustrating me too when the tests were failing.
we are not doing new_node.next = self.head because remember self.head is the dummy node before the actual head of the linked list. So to point the new node to the old head you have to do new_node.next = self.head.next( this gives the old head)
How did you make a leetcode-like editor on your website? What libraries/tools did you use?
Will make a video on it soon!
@@NeetCodeIO can you also mention how u made the node/tree editor on your website for the roadmap?
@@anonymoussloth6687 angularjs node graph library
Well I hope my data structure college course would be helpful xD. But we did it using struct in c++ and not class but I guess the same idea could be applied here.
I really need your help on knowing where I can learn the fundamentals of understanding this code. Like, I know the syntax for Python and loops and all that but I don't know anything about classes or objects or even how you could do self.head.next at 4:10. Could you guide me on where I could learn those fundamentals? Any help is appreciated, thank you.
Learn about classes, superclass/parentclass and then subclass/childclass. Along with inheritance and polymorphism. 1 month late so maybe you already got your answer but if not there's lots of guides or ask chatgpt (what I did at least)
complexity of appending at ending of the single linked list is On ?
This is great. Thanks.
Nice video. Why are you pointing the tail to the head? self.tail = self.head
Depends on scenario but basically if you create a new node
Self.head = new node
Self.tail = self.head
The second line means that they are both pointing to the new node
You could also say self.tail = new node basically in this scenario its the "same"
It means we have a dummy value regardless if we're adding/removing from the start or end of a potentially empty linked list.
when doing the get method in the single linked list, are we not counting head and tail when considering the index in the linked list as per your code if I pass 0 to the get function
I will be getting the node value next to the head and not the head.
@NeetCodeIO please do reply
He keeps the dummy head node and never removes/replaces it. I'm not sure why, it seems silly to keep this dummy node (or to even initialize with a dummy node in the first place). So yes, when creating your get method you should start the pointer at the self.head.next as he shows at 3:33
Personally, I think this entire design is flawed in keeping the dummy nodes that serve no real purpose. We should just be initializing an empty list, and if you go to insert a head or tail when there is no current head or tail, both are set to the new node or return some error stating there is no head/tail. Maintaining the dummy node just adds another variable to consider when making changes to the LinkedList that are unnecessary. Interviewers likely would appreciate seeing you handle edge cases such as this anyway.