These are great series of videos! I'm glad I came across them. One suggestion -- at the end of the videos, could you also discuss the space and time complexity for your algorithms? Thanks and keep 'em coming!
Your program will "Crash" in the second scenario (for Even Number of Elements of Linked List) --> At the last Iteration when "P" becomes a NULL, and your try to access the data from P->Next --> Result in Crash as there is no any address of P. You need to modify the if statement as follows: Option1: if(p->next == NULL) -- Modify to --> if(p && p->next == NULL) Option2: swap the positions of both the "if" statements and the second if statement would be an "else if" rather than just "if". Thanks!
perhaps, the conditions can be put in an if..else if statements.. if(p==NULL) //p is not null in the first case. so this condition is skipped// ..... else if(p->next==NULL)// valid for the first case; if the if part executes, the else if part is skipped and the execution continues unhindered!!??// I did not get your first suggestion though, could you please clarify it? what I understood is that if(p!=NULL && p->next==NULL) can be put as the first if condition.
yes, exactly you understood my first condition correctly. The first condiition if(p->next == NULL) will crash the whole program if in case the pointer "p" goes NULL. Hence, to avoid such instances, we must check if p is not NULL. just to clarify you: if (p) and if (p != NULL) both are same !
Why can't we reverse that linked list and compare with the original value at each node , If any of the respective nodes aren't equal to both , then return 0 ?
The point is finding middle node. The solution is creating a race condition. One pointer's velocity must be two times bigger than other pointer's velocity. When faster pointer reaches the end, other pointer will be in the middle. I prefer recursive way. I will find the middle by recursively then start comparing from middle nodes(even or odd problem also here) then by returning next node to upper recursive iteration and comparing prev node and returned next node and so on..
Okay, I wanna add, as we are reversing after splitting up, can't we just reverse the linkedlist at the very beginning and check if both are same? This doesn't require splitting the list. Thanks in advance
We can do it but it is not feasible as it needs traversing whole list and then comparing it. In this we are just doing half comparisons and also running loop for half. So for very long linked list it will reduce to half time complexity.
Can you please make a video on Single Pair All shortest paths problem? Given a source and a destination find all the shortest between them (there can be more than 1 path with the same length, hence all the shortest paths).
SIR YOUR WAY OF TEACHING IS GOOD, But It will be a good practice if you explain the approach first means what actually you are going to tell for this or any problem then go for the algorithm or dry run of the code. Once we know the approach we can understand the video very easily and quickly.
Awesome Explanation. I am new to algorithm yet understood this very clearly. Thank you so much , You are saving my grades and career. One small request , Can you please add the gib hub link in the description .
if you are creating a new reversed linked list that would increase the space complexity...acc to me what we can do is traverse linklst and store in a number then compare accordingly using modulo operator O(1)---space and O(n)---time
sir, we can also do it like taking two pointers at two end and traversing in the opposite direction and matching the elements,if all elements matches then its palindrom
bro it is singly linked list and in the case of singly linked list there is no means of going in the backward direction as it is not the doubly linked list thanks !!!
@Monkey D. Luffy sure , I will make it , I have my competitive programming channel , my exams are going on, after that , I will consistently upload videos there
public static void main(String[] args) { System.out.println("entier string to check palindrome :"); char[] input = new Scanner(System.in).next().toCharArray(); int forword=0; int backword=input.length-1; int mid=input.length/2; for(int i =0;i
Your videos are of great help and the language you use is so simple and understandable.Thanks.
These are great series of videos! I'm glad I came across them.
One suggestion -- at the end of the videos, could you also discuss the space and time complexity for your algorithms? Thanks and keep 'em coming!
yes sure...
When p is null, p->next will throw null pointer at this line on even length check :- if(p ->next == NULL)
exactly! should add a bound check
Check if(p == NULL) first and then check if(p->next == NULL). Just swap the checks. That should solve it.
@@seekngeek Thank you so much
I came here looking for cooper and I found gold
Why were you looking for Cooper ? what would cooper Fix ?
kuch bhi matlub
@@AbhishekKumar-qr5ql it's good and logical
you mean copper??
It throws nullpointer exception in the even case, because p is already null and your trying to access p.next()
yeah, just reverse the order of the if conditions though
Yeah just put if(!p.null && p.next=null) it will work
Just check for the even condition first, and then the odd.
We can also use stack to determine whether it's a palindrome or not.
Would you please make an example of copy constructor in the Linked List in C++? Thanks
Amazing !!Effort for us .Huge respect bro
Mr. Vivekananda ji , try to make videos on hashing
seriously dude this is really good .appreciate it
This was asked in my Nvidia experienced software interview. Please make more videos.
Oh nvidia, great
Your program will "Crash" in the second scenario (for Even Number of Elements of Linked List)
--> At the last Iteration when "P" becomes a NULL, and your try to access the data from P->Next --> Result in Crash as there is no any address of P.
You need to modify the if statement as follows:
Option1:
if(p->next == NULL) -- Modify to --> if(p && p->next == NULL)
Option2:
swap the positions of both the "if" statements and the second if statement would be an "else if" rather than just "if".
Thanks!
perhaps, the conditions can be put in an if..else if statements.. if(p==NULL) //p is not null in the first case. so this condition is skipped// ..... else if(p->next==NULL)// valid for the first case; if the if part executes, the else if part is skipped and the execution continues unhindered!!??//
I did not get your first suggestion though, could you please clarify it? what I understood is that if(p!=NULL && p->next==NULL) can be put as the first if condition.
yes, exactly you understood my first condition correctly.
The first condiition if(p->next == NULL) will crash the whole program if in case the pointer "p" goes NULL.
Hence, to avoid such instances, we must check if p is not NULL.
just to clarify you:
if (p) and if (p != NULL) both are same !
yes !! I understand that now xD Thanks...
Why can't we reverse that linked list and compare with the original value at each node , If any of the respective nodes aren't equal to both , then return 0 ?
It's a Null pointer exception for this test case: [1,0,1] . The when we have to assign secondStart = q.next.next, it will point to Null
The point is finding middle node. The solution is creating a race condition. One pointer's velocity must be two times bigger than other pointer's velocity. When faster pointer reaches the end, other pointer will be in the middle.
I prefer recursive way. I will find the middle by recursively then start comparing from middle nodes(even or odd problem also here) then by returning next node to upper recursive iteration and comparing prev node and returned next node and so on..
Or you could add all the elements to stack and then check half the LinkedList: time is O(n).... but space is O(n)
Yes koeber99 , that trick would work.
I don't see the full working code on the given link. There are only few codes, not all. Can you please share the full code for this problem?
Thanks for the wonderful video.... Please take a look into the first "if" condition, as many mentioned in the comments.... Thanks!!!! :)
Your videos are very great can you please upload videos on dynamic programming problems like gold mining, tiling problem
sir , can you make please ad_hoc algorithm playlist
in even linked list if p is nul lthe statement p->next will give segmentation fault because pointer pointing to non existing locaton
Okay, I wanna add, as we are reversing after splitting up, can't we just reverse the linkedlist at the very beginning and check if both are same? This doesn't require splitting the list. Thanks in advance
We can do it but it is not feasible as it needs traversing whole list and then comparing it. In this we are just doing half comparisons and also running loop for half. So for very long linked list it will reduce to half time complexity.
Very clear explanation.
Thank you a good explanation, your voice is the same as the tutor in the KudVenkat channel, are you the same ?? just curious !
No they are different
Sir, what an explanation, amazing💥
sir could you please make a video on XOR linked list , SKIP list , UNROLLED list..
Can you please make a video on Single Pair All shortest paths problem? Given a source and a destination find all the shortest between them (there can be more than 1 path with the same length, hence all the shortest paths).
Why not reverse the list first??
And then compare?
The first IF condition in while loop "if(p.next == null)" should be "if(p != null && p.next == null)"
dude this one condition T_T
Thank you :)
Sir please discuss how to recursion and when and where ? Especially with linked list, tree etc
SIR YOUR WAY OF TEACHING IS GOOD, But It will be a good practice if you explain the approach first means what actually you are going to tell for this or any problem then go for the algorithm or dry run of the code.
Once we know the approach we can understand the video very easily and quickly.
Awesome Explanation. I am new to algorithm yet understood this very clearly. Thank you so much , You are saving my grades and career. One small request , Can you please add the gib hub link in the description .
why cant we just reverse the entire linked list and then check?
if you are creating a new reversed linked list that would increase the space complexity...acc to me what we can do is traverse linklst and store in a number then compare accordingly using modulo operator O(1)---space and O(n)---time
how will this work for a b c c b ?
but we also use the reverse of linked list approach also
while(i
we cannot back traverse linked list
you are doing great job sir!!
sir, we can also do it like taking two pointers at two end and traversing in the opposite direction and matching the elements,if all elements matches then its palindrom
bro it is singly linked list and in the case of singly linked list there is no means of going in the backward direction as it is not the doubly linked list
thanks !!!
very good with explanations..........always checkout this channel, dope
Nice video.God bless you..
Thank you. This is very clear.
Very nice explanation.
What would be space complexity of this solution ?
I dont think space complexity will be an issue here as all you require is just three extra pointers p,q and start
you can rather do it by recursion, it can be more simple and small.....
@Monkey D. Luffy sure , I will make it , I have my competitive programming channel , my exams are going on, after that , I will consistently upload videos there
Genius.
NICE SUPER EXCELLENT MOTIVATED
sir can u provide a link to a source code...i am unable to find it
Amazing vedio
Hello sir....i need a video to find theLength of longest palindrome list in a linked list using O(1) extra space.
explain very clear! Big thanks!
plzz give me a function that check linked list is sorted or not? plzz give me code
amazing explanation , thank you so much :)
hello sir....I need program for reverse a linked list from position n to m... n=2 and m=5 LL 1->2->3->4->5->6 output becomes 1 5 4 3 2 6
Excellent 🙏🙏
This approch is ok but is not correct for all cases
Really your videos are excellent
big an sir love you from odisha❤❤❤❤
very useful videos.. keep posting sir
sir pls provide with the code???? not available on github
I will give the link
Nice video sir. One query ? Does it work for string "aba" ?
awesome explanation. Thanx a lot sir.
Thanks Sushmita..!
Thank you sir
great video!!!
Amazing!
public static void main(String[] args) {
System.out.println("entier string to check palindrome :");
char[] input = new Scanner(System.in).next().toCharArray();
int forword=0;
int backword=input.length-1;
int mid=input.length/2;
for(int i =0;i
I think you write for array,
But question is singly linked list
Though iam not sure whether yoy written for singly linked list or not
there is a bug in the algo
Thank you sir. Very useful video
welcome vaibes.!
didn't find the program in github!
check this: github.com/vivekanand44/codes-RUclips-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp
thank you brother
This is flawed , try to run the code against 1-2-1-2-1-2-1
please put the lilnk to github
github.com/vivekanand44/codes-RUclips-videos
Perfect explanation sir. Thanks :)
Thanks Aditya..!
sir tree ke question v dalo
hello brother plz share github link
thanks
ye bro can you make the videos on bucket sort plZ
Thanks ❤you save me
Thank u sir for your explanation. I could not find your source code in github.com/vivekanda44. Can u pls give the correct link?
github.com/vivekanand44/codes-RUclips-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp
Thank u so much sir..