Check if the singly Linked List is a Palindrome

  Рет қаралды 79,035

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер
@vatsalanand9417
@vatsalanand9417 4 жыл бұрын
Your videos are of great help and the language you use is so simple and understandable.Thanks.
@farazromani
@farazromani 7 жыл бұрын
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!
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
yes sure...
@anweshvalleshetti3499
@anweshvalleshetti3499 6 жыл бұрын
It throws nullpointer exception in the even case, because p is already null and your trying to access p.next()
@avinashkhetri9575
@avinashkhetri9575 5 жыл бұрын
yeah, just reverse the order of the if conditions though
@Ashish.Shukla9
@Ashish.Shukla9 5 жыл бұрын
Yeah just put if(!p.null && p.next=null) it will work
@ezrahn
@ezrahn 5 жыл бұрын
Just check for the even condition first, and then the odd.
@sergiojimenez3445
@sergiojimenez3445 7 жыл бұрын
I came here looking for cooper and I found gold
@SnehasishGhoshSg
@SnehasishGhoshSg 6 жыл бұрын
Why were you looking for Cooper ? what would cooper Fix ?
@AbhishekKumar-qr5ql
@AbhishekKumar-qr5ql 5 жыл бұрын
kuch bhi matlub
@siddhartharaja9413
@siddhartharaja9413 4 жыл бұрын
@@AbhishekKumar-qr5ql it's good and logical
@saketkumar7335
@saketkumar7335 4 жыл бұрын
you mean copper??
@ProgrammingTutorials1M
@ProgrammingTutorials1M 5 жыл бұрын
We can also use stack to determine whether it's a palindrome or not.
@TechTanka
@TechTanka 7 жыл бұрын
When p is null, p->next will throw null pointer at this line on even length check :- if(p ->next == NULL)
@jamesqiu6715
@jamesqiu6715 7 жыл бұрын
exactly! should add a bound check
@seekngeek
@seekngeek 7 жыл бұрын
Check if(p == NULL) first and then check if(p->next == NULL). Just swap the checks. That should solve it.
@debanjankuri5274
@debanjankuri5274 4 жыл бұрын
@@seekngeek Thank you so much
@VanTran-zf7mg
@VanTran-zf7mg 4 жыл бұрын
Would you please make an example of copy constructor in the Linked List in C++? Thanks
@pankushmahajan4598
@pankushmahajan4598 6 жыл бұрын
Mr. Vivekananda ji , try to make videos on hashing
@ProgrammingArena
@ProgrammingArena 6 жыл бұрын
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!
@soumilyade1057
@soumilyade1057 6 жыл бұрын
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.
@ProgrammingArena
@ProgrammingArena 6 жыл бұрын
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 !
@soumilyade1057
@soumilyade1057 6 жыл бұрын
yes !! I understand that now xD Thanks...
@rohankrishna156
@rohankrishna156 4 жыл бұрын
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
@koeber99
@koeber99 7 жыл бұрын
Or you could add all the elements to stack and then check half the LinkedList: time is O(n).... but space is O(n)
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
Yes koeber99 , that trick would work.
@satvikkhare1844
@satvikkhare1844 2 жыл бұрын
This was asked in my Nvidia experienced software interview. Please make more videos.
@SK-qn5ry
@SK-qn5ry 2 жыл бұрын
Oh nvidia, great
@rishabhsahu5257
@rishabhsahu5257 4 жыл бұрын
Amazing !!Effort for us .Huge respect bro
@cemyasar4858
@cemyasar4858 5 жыл бұрын
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..
@shailbenq
@shailbenq 6 жыл бұрын
The first IF condition in while loop "if(p.next == null)" should be "if(p != null && p.next == null)"
@talhacoder5084
@talhacoder5084 3 жыл бұрын
dude this one condition T_T Thank you :)
@r3fl3xplays36
@r3fl3xplays36 6 жыл бұрын
sir could you please make a video on XOR linked list , SKIP list , UNROLLED list..
@informative_idiot-x6e
@informative_idiot-x6e 6 жыл бұрын
Thanks for the wonderful video.... Please take a look into the first "if" condition, as many mentioned in the comments.... Thanks!!!! :)
@HarshKumar-nh6be
@HarshKumar-nh6be 4 жыл бұрын
Your videos are very great can you please upload videos on dynamic programming problems like gold mining, tiling problem
@palagatideepthireddy3659
@palagatideepthireddy3659 6 жыл бұрын
in even linked list if p is nul lthe statement p->next will give segmentation fault because pointer pointing to non existing locaton
@uzairkhurshid3036
@uzairkhurshid3036 7 жыл бұрын
seriously dude this is really good .appreciate it
@mdanishossain026
@mdanishossain026 2 жыл бұрын
sir , can you make please ad_hoc algorithm playlist
@PrashantNigam
@PrashantNigam 5 жыл бұрын
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).
@rajatbais6388
@rajatbais6388 5 жыл бұрын
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.
@parthsinghparihar1904
@parthsinghparihar1904 4 жыл бұрын
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 ?
@shubhammalik9418
@shubhammalik9418 4 жыл бұрын
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?
@alifruslan2728
@alifruslan2728 4 жыл бұрын
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
@dankyt9249
@dankyt9249 4 жыл бұрын
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.
@AddieInGermany
@AddieInGermany 7 жыл бұрын
Sir please discuss how to recursion and when and where ? Especially with linked list, tree etc
@devotion_surya3741
@devotion_surya3741 4 жыл бұрын
Sir, what an explanation, amazing💥
@chetanshrivastava3762
@chetanshrivastava3762 3 жыл бұрын
Nice video.God bless you..
@rohan5713
@rohan5713 6 жыл бұрын
but we also use the reverse of linked list approach also while(i
@nitinjangra5164
@nitinjangra5164 5 жыл бұрын
we cannot back traverse linked list
@bharathik6479
@bharathik6479 4 жыл бұрын
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 .
@kalpatarupodder708
@kalpatarupodder708 6 жыл бұрын
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
@SOURABHGOLCHHABCE
@SOURABHGOLCHHABCE 6 жыл бұрын
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 !!!
@shwetayadav3288
@shwetayadav3288 4 жыл бұрын
Very clear explanation.
@viewgood
@viewgood 4 жыл бұрын
Thank you a good explanation, your voice is the same as the tutor in the KudVenkat channel, are you the same ?? just curious !
@adi_sekar
@adi_sekar 4 жыл бұрын
No they are different
@ganeshjaggineni4097
@ganeshjaggineni4097 2 жыл бұрын
NICE SUPER EXCELLENT MOTIVATED
@shloch2007
@shloch2007 5 жыл бұрын
very good with explanations..........always checkout this channel, dope
@prashantshukla7203
@prashantshukla7203 7 жыл бұрын
you are doing great job sir!!
@GeekXpert
@GeekXpert 5 жыл бұрын
why cant we just reverse the entire linked list and then check?
@nitinjangra5164
@nitinjangra5164 5 жыл бұрын
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
@parambharti7095
@parambharti7095 5 жыл бұрын
Very nice explanation.
@ArpitDhamija
@ArpitDhamija 5 жыл бұрын
you can rather do it by recursion, it can be more simple and small.....
@ArpitDhamija
@ArpitDhamija 4 жыл бұрын
@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
@ShivaniSingh-mq4pv
@ShivaniSingh-mq4pv 3 жыл бұрын
Amazing vedio
@16avnisharma
@16avnisharma 7 жыл бұрын
very useful videos.. keep posting sir
@harshtulsyan9894
@harshtulsyan9894 6 жыл бұрын
Hello sir....i need a video to find theLength of longest palindrome list in a linked list using O(1) extra space.
@mohammedsadiq1567
@mohammedsadiq1567 4 жыл бұрын
Why not reverse the list first?? And then compare?
@priyanshu4016
@priyanshu4016 3 жыл бұрын
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
@SK-qn5ry
@SK-qn5ry 2 жыл бұрын
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
@deepakborah8335
@deepakborah8335 7 жыл бұрын
Really your videos are excellent
@sallyzhangt
@sallyzhangt 6 жыл бұрын
Thank you. This is very clear.
@brijyotchawla3247
@brijyotchawla3247 5 жыл бұрын
What would be space complexity of this solution ?
@gunslingerarthur5865
@gunslingerarthur5865 5 жыл бұрын
I dont think space complexity will be an issue here as all you require is just three extra pointers p,q and start
@ridimamittal4064
@ridimamittal4064 4 жыл бұрын
amazing explanation , thank you so much :)
@srafayal
@srafayal 2 жыл бұрын
big an sir love you from odisha❤❤❤❤
@hibritto
@hibritto 2 жыл бұрын
Genius.
@suriyapriyajayavel1176
@suriyapriyajayavel1176 7 жыл бұрын
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
@gurpeetsingh9152
@gurpeetsingh9152 6 жыл бұрын
sir can u provide a link to a source code...i am unable to find it
@pkl520
@pkl520 7 жыл бұрын
explain very clear! Big thanks!
@VishalYadav-ss4qv
@VishalYadav-ss4qv 4 жыл бұрын
Excellent 🙏🙏
@divyagupta5195
@divyagupta5195 4 жыл бұрын
how will this work for a b c c b ?
@sushmitanigam4979
@sushmitanigam4979 7 жыл бұрын
awesome explanation. Thanx a lot sir.
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
Thanks Sushmita..!
@jeezradz
@jeezradz 4 жыл бұрын
great video!!!
@ZeeshanKhan-mo9mu
@ZeeshanKhan-mo9mu 7 жыл бұрын
plzz give me a function that check linked list is sorted or not? plzz give me code
@pawanbasu6777
@pawanbasu6777 6 жыл бұрын
didn't find the program in github!
@hardikrana2210
@hardikrana2210 6 жыл бұрын
check this: github.com/vivekanand44/codes-KZbin-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp
@vaibesb4u
@vaibesb4u 7 жыл бұрын
Thank you sir. Very useful video
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
welcome vaibes.!
@shaikshabbir4479
@shaikshabbir4479 7 жыл бұрын
Nice video sir. One query ? Does it work for string "aba" ?
@bhavyanayyer3391
@bhavyanayyer3391 3 жыл бұрын
sir pls provide with the code???? not available on github
@vivekanandkhyade
@vivekanandkhyade 3 жыл бұрын
I will give the link
@AddieInGermany
@AddieInGermany 7 жыл бұрын
Perfect explanation sir. Thanks :)
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
Thanks Aditya..!
@ayoubaoumrani3200
@ayoubaoumrani3200 11 ай бұрын
Thank you sir
@vivekgr3001
@vivekgr3001 4 жыл бұрын
Amazing!
@HarshaVardhan-jf9sd
@HarshaVardhan-jf9sd 5 жыл бұрын
there is a bug in the algo
@ghoshdipan
@ghoshdipan 4 жыл бұрын
This approch is ok but is not correct for all cases
@webTVfiction
@webTVfiction 6 жыл бұрын
thank you brother
@gurmeetchawla8362
@gurmeetchawla8362 6 жыл бұрын
please put the lilnk to github
@hardikrana2210
@hardikrana2210 6 жыл бұрын
github.com/vivekanand44/codes-KZbin-videos
@ashishsinha8893
@ashishsinha8893 7 жыл бұрын
ye bro can you make the videos on bucket sort plZ
@kapztcs
@kapztcs 4 жыл бұрын
This is flawed , try to run the code against 1-2-1-2-1-2-1
@aka_gym_lad
@aka_gym_lad 4 жыл бұрын
sir tree ke question v dalo
@imaneorj512
@imaneorj512 Жыл бұрын
Thanks ❤you save me
@ashishsinha8893
@ashishsinha8893 7 жыл бұрын
hello brother plz share github link
@md.abdullahal-alamin8059
@md.abdullahal-alamin8059 7 жыл бұрын
thanks
@saranyasaravanan7780
@saranyasaravanan7780 7 жыл бұрын
Thank u sir for your explanation. I could not find your source code in github.com/vivekanda44. Can u pls give the correct link?
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
github.com/vivekanand44/codes-KZbin-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp
@saranyasaravanan7780
@saranyasaravanan7780 7 жыл бұрын
Thank u so much sir..
Add two numbers represented by linked lists
16:26
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 65 М.
Check If Linked List is Palindrome
8:52
CppNuts
Рет қаралды 3,8 М.
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН
كم بصير عمركم عام ٢٠٢٥😍 #shorts #hasanandnour
00:27
hasan and nour shorts
Рет қаралды 8 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
Swap nodes in a linked list without swapping data (Very Easy Explanantion)
20:54
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 56 М.
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 915 М.
L10. Check if a LinkedList is Palindrome or Not | Multiple Approaches
20:02
Palindrome Linked List - Leetcode 234 - Python
11:06
NeetCode
Рет қаралды 100 М.
Remove Duplicates From Sorted Linked List
20:05
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 31 М.
L15. Find the length of the Loop in LinkedList
14:01
take U forward
Рет қаралды 61 М.
Merge two sorted Linked Lists to form a new Sorted Linked List
13:59
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 172 М.
Reverse a Single Linked List
11:57
Neso Academy
Рет қаралды 280 М.
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН