L2. Deletion and Insertion in LL | 8 Problems

  Рет қаралды 250,403

take U forward

take U forward

Күн бұрын

Пікірлер: 245
@samxd4296
@samxd4296 Жыл бұрын
0:00 Intro 0:34 Deletion of the head of LL 6:18 Deletion of the tail of LL 15:47 Deletion of the Kth element of LL 30:14 Delete the element with value X 32:15 Insertion at the head of LL 35:15 Insertion at the tail of LL 38:41 Insertion at the Kth position 51:22 Insertion before the value X Thank You Striver for the Playlist and your hard work
@GotetiKrishnasrikar
@GotetiKrishnasrikar 4 ай бұрын
@immortal6978
@immortal6978 Жыл бұрын
A hell lot of hardweork for the community. Hat's off your dedication to coding. Hit like on video if Agreed.
@AnshGupta-pr7qo
@AnshGupta-pr7qo Ай бұрын
How could someone be so perfect at explaining.....literally hats off to you striver If in life i ever had a chance to meet or see you it'll be one of mt best day
@5640_GlenaSAHA
@5640_GlenaSAHA 5 ай бұрын
you are the best one to teach linked list in the easiest manner, I wasted my whole third semester understanding linked list but still failed. But you are really amazing!!!!
@chrish4403
@chrish4403 2 ай бұрын
So grateful , Linked list is a topic ive been avoiding to learn from my boards due to lack of understanding, but in just two videos you have made me so well versed with linked list, wish i found this video two years ago,
@vedikamishra009
@vedikamishra009 5 күн бұрын
same, but 2 years ago it didn't exist sadly :(
@loremvampire6343
@loremvampire6343 Жыл бұрын
I was waiting for this playlist since one month. Thank you so much Sir
@ronakvaghela2714
@ronakvaghela2714 3 ай бұрын
One of the best coding content on the whole youtube. You're an inspiration to everyone and a great example of how hardwork looks like. Thanyou so much for doing this. you deserve everything you wish for and hope to see such content more from you.
@ShubhraneelChakraborty-cj8zm
@ShubhraneelChakraborty-cj8zm 4 ай бұрын
For insertion of a node at the head of the linked list, we can also do this: Node temp=head; head=val; head.next=temp; return head; What its doing is that, the previous head is being assigned to a temporary pointer, and the new node being inserted (val) is being assigned to the initial head pointer (head), a simple swap. Then the head's next is being assigned the temporary pointer (holding the initial head) to link the new head and the previous one. Hope that helps. And thank you Raj bhaiya for such an amazing video again, the explanation was so clear.
@GirishaMalani-fs4ch
@GirishaMalani-fs4ch 4 ай бұрын
but then what will be temp->next?
@ShubhraneelChakraborty-cj8zm
@ShubhraneelChakraborty-cj8zm 3 ай бұрын
@@GirishaMalani-fs4ch Forgot to mention, it is in Java, so it will be collected by the garbage collector. For C++, you need to free that pointer.
@publicuses8589
@publicuses8589 Жыл бұрын
Striver bhaiya u r a gemmmmm lot's of respect for u 🫡🫡
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
Notes 33:33 Insert at head 50:01 Delete Nicely done
@Ranganadhamkrishnachaitanya27
@Ranganadhamkrishnachaitanya27 8 ай бұрын
How code will work I'm confused
@AmanSharma-xy1qm
@AmanSharma-xy1qm 11 ай бұрын
All the video lectures and the articles helped me a lot to gain confidence in DSA and will be helping me in the interviews. Thank you Striver bhaiya for bringing such amazing content for free.
@anuragprasad6116
@anuragprasad6116 9 ай бұрын
For deletion at k index, you can check if(cnt == k-1) and perform curr->next = curr->next->next; instead of keeping a previous pointer.
@purvamjain4953
@purvamjain4953 3 ай бұрын
it wil give u error, assume u have 4 elements and they asked to remove 5th element. with cnt=k-1 it will try to access next element of null which will throw error unless u catch it manually
@sanjayutchula7849
@sanjayutchula7849 2 ай бұрын
In order to avoid this we can maintain a int size variable in class and declare it public update every time we add or delete node and for deleting a kth node we can check at starting if it exceeds the boundaries and throw an error else we can run a for loop for k times and move the temp pointer to reach before which we want to delete ​@@purvamjain4953
@VivekKumar-kx2zf
@VivekKumar-kx2zf 2 ай бұрын
@@purvamjain4953 no that can also be skipped using a if condition.. Look at this code : static Node DeleteAny(Node head, int k) { Node temp = head; if(k == 1) { head = head.next; return head; } for(int i = 1; temp != null;i++) { if(i == k-1 && temp.next!=null) { temp.next = temp.next.next; } temp = temp.next; } return head; }
@mdfaizanmdfaizan6041
@mdfaizanmdfaizan6041 Ай бұрын
​@@purvamjain4953we can apply for a condition before
@santhoshl-zq1op
@santhoshl-zq1op 26 күн бұрын
But , at the starting itself , we check the condition if( k > lengthof LL ) return head;
@5640_GlenaSAHA
@5640_GlenaSAHA 5 ай бұрын
believe me on this when i say he is the best!!
@utkarshsingh09
@utkarshsingh09 2 ай бұрын
His teaching skills!!! Hats off!
@prathameshjadhav2942
@prathameshjadhav2942 Жыл бұрын
Next level teaching ❤
@hareshnayak7302
@hareshnayak7302 7 ай бұрын
Understood,Thanks striver for this amazing video.
@S3aw0lf
@S3aw0lf 9 ай бұрын
Superb explanation, was able to do the code by myself starting from 2nd video after understanding you explanations.
@dipingrover1970
@dipingrover1970 3 ай бұрын
Such a hard topic explained in best way possible Thanks a lot man 😊.
@vaishnavi.pvaishnavi.p8474
@vaishnavi.pvaishnavi.p8474 9 ай бұрын
superb explanation sir...... i want to listen you more and more
@PCCOERCoder
@PCCOERCoder Күн бұрын
Lecture successfully completed on 26/11/2024 🔥🔥
@ompawar9791
@ompawar9791 Жыл бұрын
I searched for this kind of videoes from last few days. Now i got that man ->striver.........YOU CREATED ME AS A POINTER WHERE I STORED ADDRESS OF YOUR CHANNEL IN MY HEART❣❣❣❣❣❣❣❣
@ompawar9791
@ompawar9791 Жыл бұрын
wow
@pranaycc
@pranaycc Жыл бұрын
Crisp And Detailed, 💕💕
@chetna253
@chetna253 2 ай бұрын
a lot of hardwork ...respect bruh
@harshitgarg2820
@harshitgarg2820 Жыл бұрын
Completed this video and done all the 11 questions of the sheet.✅✅
@himanshukaushik9223
@himanshukaushik9223 10 ай бұрын
Bro last 2 questions ma compilation error bta Raha insertion ma sheet ka
@harshitgarg2820
@harshitgarg2820 10 ай бұрын
@@himanshukaushik9223 bhai typos me error hogi, ek baar dobara check kro fir run krna, agr vs code use krr rhe ho toh mingw ko reinstall krke dekho
@himanshukaushik9223
@himanshukaushik9223 10 ай бұрын
Bhai coding ninja pa last 2 question compile error bta rahe hai
@Ady-tf1jm
@Ady-tf1jm 3 ай бұрын
Best Playlist for beginners.
@prajjwalsinghrathore9458
@prajjwalsinghrathore9458 Жыл бұрын
Thanks bhayya for the playlist, we appreciate it , it would be good if you add time-stamp to it.
@Ravithasingh089
@Ravithasingh089 Жыл бұрын
Glad to be the First viewer brooooo🎉🎉🎉. Thank you so much for this quality content.!!
@AtanuDebnath
@AtanuDebnath 5 ай бұрын
Raj Dada , Love you! ❤❤❤ You make the hard things look so easy!
@GauravGupta-no7sf
@GauravGupta-no7sf 10 ай бұрын
00:04 Deletion and insertion in linked lists 02:21 Freeing memory in C++ and Java 06:58 To delete the last element in a linked list, the list must have at least two elements. 09:34 Deleting the tail element from a linked list 14:28 Demonstration of removing elements from a linked list in Java. 16:46 Deleting elements from a linked list 21:04 Discussing traversal and conditions for stopping 23:27 Managing deletion and insertion in a linked list 28:03 Removing elements from a linked list in Java 30:23 Deleting elements from a linked list based on given value. 34:35 Inserting before and after the head in linked list 36:44 Inserting a new node at the end of the linked list 41:06 Insertion in linked list at different positions 43:21 Traversing and manipulating temporary in linked list 48:12 Covering all the H cases for node insertion in a linked list 50:27 Inserting and deletion in linked list 54:42 Insertion before a value in a linked list
@glife54
@glife54 9 ай бұрын
Ai
@DeepikaaSelvam
@DeepikaaSelvam 3 ай бұрын
Waiting for Strings Playlist !.. No one is talking about the String Concept!!!
@MOHAMMEDMOJAHID-rg8sc
@MOHAMMEDMOJAHID-rg8sc 3 ай бұрын
Me too
@Rohit-ht8kd
@Rohit-ht8kd Ай бұрын
at 29th min the code for if(k == 1) is head = head.next; return head: but you have written Node temp = head: return head;
@lordgaming7178
@lordgaming7178 24 күн бұрын
Thank you for the explanation
@prathamrajsrivastava9807
@prathamrajsrivastava9807 11 ай бұрын
hey striver... when's the strings playlist coming out??
@sauravkumar9900
@sauravkumar9900 11 ай бұрын
Bhaiya please make a playlist videos on Strings from basic to advance
@uchihaitachi5376
@uchihaitachi5376 9 күн бұрын
Striver love you bro how can you make things very simple thank s bro❤
@AtulPal-i5s
@AtulPal-i5s 2 ай бұрын
Waiting for String Playlist
@omkarsawant9267
@omkarsawant9267 6 ай бұрын
Guys during Insertion kindly modify your node constructor or else you will get argument error. Modified code below-> class Node { public: int data; Node *next; public: Node(int data1, Node* nextNode = nullptr) { data = data1; next = nextNode; // argument added } }; Below Insert Node code--> Node* insertHead(Node* head, int val){ Node* temp = new Node(val, head); return temp; } int main() { vector arr = {2, 5, 8, 7}; Node *head = convertArr2LL(arr); head = insertHead(head, 18); print(head); return 0; }
@JalalMujawar
@JalalMujawar 3 ай бұрын
Code for removing a node without knowing the head: public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; }
@newbie8051
@newbie8051 4 ай бұрын
0:34 ha, my initial thought was to use a slow and fast pointer, and when fast pointer approaches the node to be deleted, we skip it by having next of slow pointer be the next node
@HarishKumar-jm5bk
@HarishKumar-jm5bk Жыл бұрын
Striver can u please make series on binary numbers number theory and bit manipulation there is no video on youtube please make this video if possible
@sonyshaw9964
@sonyshaw9964 6 ай бұрын
Indeed supreme quality article
@SanthoshaK-px8rq
@SanthoshaK-px8rq 5 ай бұрын
public Node DeleteK_ele(Node head, int k){ Node temp = head; if(k == 1){ temp = head.next; return temp; } int i=1; while(i
@AbhishekRanjan-wk7xp
@AbhishekRanjan-wk7xp 4 ай бұрын
but how will you handle the case when k>length of linked list
@ARNAVGUPTA-s1m
@ARNAVGUPTA-s1m 2 ай бұрын
If we create a dummy node before head, we will not have to worry about edge cases. Just remember to return dummy->next.
@vivekkumar841
@vivekkumar841 9 ай бұрын
awesomee lecture bhaiya!!!
@beaware70
@beaware70 Жыл бұрын
Great explaination sir❤❤❤❤
@doremon81072
@doremon81072 7 ай бұрын
loved it, Jai ho striver bhaiya
@Ayeshasingh720
@Ayeshasingh720 4 ай бұрын
so.... finally i m understanding LL🙂
@shivamswarnkar7763
@shivamswarnkar7763 26 күн бұрын
In the very last code which he has written we have to write while(temp.next.next not equal to null) instead of while temp.next not equal to null. If I am wrong, would be grateful for corrections.
@gyanendrasonkar3144
@gyanendrasonkar3144 4 күн бұрын
I feel the condition is fine and safe to have. eg: case1) 1->null key = 1, ele= 2 if (head.val == key) return new Node(ele, head) works. 2->1->null Case 2) 1->2->null key =2, ele=3. temp =head; So , temp points to head, temp @1. (temp,head) 1 ----> 2->null if temp->next->data is same key( 2==2) , yes create a node, x = new Node(ele, temp->next) x 3---> 2---> null ^ | 1(temp,head) temp -> next = x; x 3---> 2---> null ^ | 1(temp,head) 1->3->2->null Another example::: 1-2-3-5-6-null key =5, ele 4 when we found the key, ( temp->next-data== key), stop here and add the node ^^^ head temp 1-----2-----3--------5---------6---null x = new Node(ele, temp->next) h temp x 1----2-----3 4------5----6--null ( remember temp next still pointing to 5 , can't draw ^^) temp -> next = x; h 1-2-3-4-5-6-null I hope it is cleared now...
@venkat.sairam
@venkat.sairam 11 ай бұрын
🎯 Key Takeaways for quick navigation: 00:03 🌐 *Introduction to the video on deletion and insertion in linked lists, covering eight different problems.* 00:30 🗑️ *Explanation of deleting the head of a linked list.* 01:25 🔄 *Moving the head to the next node as part of deletion process.* 02:49 💻 *In C++, using `free` or `delete` to remove a node; not needed in Java due to garbage collection.* 03:56 🧑‍💻 *Writing a function to return the new head after removing the original head.* 06:10 📌 *Detailed explanation of deleting the tail of a linked list.* 07:41 🖊️ *Writing code for deleting the tail of a linked list.* 11:35 ✂️ *Description of removing the tail by pointing the second last element to null.* 14:25 💬 *Transitioning the explanation to Java implementation.* 16:29 🔍 *Discussing deletion of a specific element in the linked list based on its position.* 19:15 👨‍🏫 *Explaining the code for deleting a node at a given position.* 21:42 🤔 *Consideration of edge cases in linked list manipulation.* 26:36 🖥️ *Demonstrating code for removing an element at a specific position.* 29:14 🚀 *Transitioning to Java implementation for element deletion.* 32:14 🔀 *Shifting focus to insertion in linked lists, starting with inserting at the head.* 35:12 ➕ *Discussing insertion at the end (tail) of the linked list.* 38:43 📍 *Explaining insertion at a given position in the linked list.* 42:48 📝 *Writing code for inserting a node at a specific position.* 51:04 🎯 *Discussing insertion of a node before a node with a given value.* 54:02 ✨ *Concluding with a summary of all the linked list operations covered.* Made with HARPA AI
@vivekgautam9766
@vivekgautam9766 2 ай бұрын
Make a series on strings from basics to advance.
@AnujTiwari-g8o
@AnujTiwari-g8o 2 ай бұрын
you are a star bro...🔥🔥🔥🔥🔥🔥
@Shikaslad-s5f
@Shikaslad-s5f 3 ай бұрын
don't know what might be the issue but if k = n+1 where n = length of LL it is still removing the last element from LL Here is the code Node* removek(Node* head, int k){ if(head == NULL)return head; if(k==1){ Node* temp = head; head = head->next; delete temp; return head; } int count = 0; Node* prev = NULL; Node* temp = head; while(temp != NULL){ count++; if(count == k){ prev->next = prev->next->next; delete temp; break; } prev = temp; temp = temp->next; } return head; }
@rohitkuttum3102
@rohitkuttum3102 3 ай бұрын
in delete tail remeber to free the head if (head->next==null) while using c++ . ignore java,python,js developers.
@dhikshitha7694
@dhikshitha7694 Жыл бұрын
Awesome video! In deletion of last/tail node in the base case if either the length is 0 or 1 we return null, but when length is 1 we should free the allocated memory that is delete head and then return nullptr right?
@saitejanedunoori5451
@saitejanedunoori5451 6 ай бұрын
great work and thank you THALA
@AshokKumar-td2qo
@AshokKumar-td2qo 10 ай бұрын
Hey Striver you are my inspiration. Very thank you for LinkedList playlist ❤❤ Please suggest dbms in english video i can't understand hindi
@ThakurIsGeek
@ThakurIsGeek 10 ай бұрын
good work i have learn alot from you
@adebisisheriff159
@adebisisheriff159 9 ай бұрын
Thanks so much Striver!!!!
@MyAnish22
@MyAnish22 Жыл бұрын
@25:40 timestamp - we can also write prev->next = temp-> next? Also, if k==4 then tail gets deleted but what about indicating prev as the new Tail? Can understand, if any node pointing to nullptr is a tail then its fine.
@khushisaraswat5826
@khushisaraswat5826 4 ай бұрын
Nice tutorials u have removed the need of such paid dsa courses....
@purvshah4260
@purvshah4260 Жыл бұрын
god level explaination
@BadalJena-oh6qu
@BadalJena-oh6qu 3 ай бұрын
inserting at kth positition 38:00
@36nchiranjeevi53
@36nchiranjeevi53 11 ай бұрын
Great explanation
@HitanshuRathi-zz5vn
@HitanshuRathi-zz5vn 12 күн бұрын
Understood Thanks brother
@junaidmetkari6365
@junaidmetkari6365 4 ай бұрын
waiting for string playlist🙂🙂
@freeandreliablejeeprep820
@freeandreliablejeeprep820 2 ай бұрын
Srila prabhupada, Hare Krishna
@hardikpatel352
@hardikpatel352 6 ай бұрын
Thanks a lot striver, understood
@deepakbhatt555
@deepakbhatt555 11 ай бұрын
nicely explained !
@vilen2685
@vilen2685 10 ай бұрын
Thankuhh sir for giving code in java !!!!
@NewtonVarma
@NewtonVarma 5 ай бұрын
Hey @takeUforward striver please upload string lectures,
@oppie335
@oppie335 9 ай бұрын
fantastic 👏
@albela7434
@albela7434 7 ай бұрын
greatttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt lecture i ever watched
@ShubhamKumar-me7py
@ShubhamKumar-me7py 6 ай бұрын
hey can we do dsa together
@amanasrani6405
@amanasrani6405 3 ай бұрын
Thank You so muchhhhh ❤❤❤❤❤🙏🏻, understood
@TON-108
@TON-108 10 ай бұрын
Understood, Thanks!
@alphaCont
@alphaCont 10 ай бұрын
fantastic man
@RaviKumar-sn6tu
@RaviKumar-sn6tu 7 ай бұрын
besst video I have seen
@anshukumari6226
@anshukumari6226 10 ай бұрын
Thanks for the video!
@NazeerBashaShaik
@NazeerBashaShaik 7 ай бұрын
Understood, thank you
@jainkokila2335
@jainkokila2335 2 ай бұрын
55:30 found is bool it cannot store 1 it can store true to solve our purpose
@AniketKumar-hf2bo
@AniketKumar-hf2bo 8 ай бұрын
thnx for amazing video ❤❤❤👌👌👍👍👍👍
@DevashishJose
@DevashishJose 8 ай бұрын
Thank you so much.Understood
@tekashi6943
@tekashi6943 Ай бұрын
Understood❤
@itsksujan
@itsksujan 6 ай бұрын
35:00 don't we have to update the head to point to the new node that is inserted at the head ?
@deadlock4919
@deadlock4919 6 ай бұрын
Just thank you 👍🏻
@nrted3877
@nrted3877 5 ай бұрын
Thanks striver bhai
@Tbm4545
@Tbm4545 Ай бұрын
32:22 insertion node
@Ergoswami
@Ergoswami 7 ай бұрын
Completed!
@krishaelle8309
@krishaelle8309 9 ай бұрын
Thank you
@yetohkardiya
@yetohkardiya 3 ай бұрын
🐐GOAT 🐐
@YourCodeVerse
@YourCodeVerse 10 ай бұрын
Understood✅🔥🔥
@stutimishra5727
@stutimishra5727 4 ай бұрын
u are gem
@supernova4467
@supernova4467 Жыл бұрын
idk no why i cant do problem solving i can understand dsa topics pretty easily but cp feels very hard to me like this year codevita questions like orchard , vip cafe , maze runner i could not figure out them im really ashamed of myself
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
You start with A20J Ladder
@sharaneshwar1305
@sharaneshwar1305 Күн бұрын
Node *deletekele(Node *head,int k){ if(head== NULL || head->next==nullptr){ return nullptr; } int cnt=1; Node *temp=head; Node *x; if(k==1){ x=temp->next; delete temp; return x; } while(temp){ if(cnt==k-1){ x=temp->next->next; delete temp->next; temp->next=x; } temp=temp->next; cnt++; } return head; } can we use this logic for deletion raj sir
@SYCOA12CHAITANYAASOLE
@SYCOA12CHAITANYAASOLE 3 ай бұрын
Understood !!
@RoshanKumar-jf5bx
@RoshanKumar-jf5bx Жыл бұрын
Superb
@sarthakvarshney3830
@sarthakvarshney3830 Жыл бұрын
You are great bhaiya
@bullymaguire2335
@bullymaguire2335 6 ай бұрын
is there a python playlist for linkedlist im unable to find it .
@Abhishekthakur-mg4el
@Abhishekthakur-mg4el Жыл бұрын
thank you bhiya ❤
@dronnema203
@dronnema203 3 ай бұрын
understood!!
@harshkumartiwari3563
@harshkumartiwari3563 3 ай бұрын
amazing:::::::::
L3. Introduction to Doubly LinkedList | Insertions and Deletions
1:04:07
take U forward
Рет қаралды 185 М.
L1. Introduction to LinkedList | Traversal | Length | Search an Element
45:17
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 2,7 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 119 МЛН
do you know how "return" works under the hood? (are you SURE?)
5:08
Coding Interviews Be Like
5:31
Nicholas T.
Рет қаралды 6 МЛН
Visualizing transformers and attention | Talk for TNG Big Tech Day '24
57:45
Reacting to Controversial Opinions of Software Engineers
9:18
Fireship
Рет қаралды 2,1 МЛН
L4. Reverse a DLL | Multiple Approaches
18:30
take U forward
Рет қаралды 98 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 151 М.
L9. Reverse a LinkedList | Iterative and Recursive
32:42
take U forward
Рет қаралды 163 М.
10 weird algorithms
9:06
Fireship
Рет қаралды 1,3 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39