Check if the singly Linked List is a Palindrome

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024

Комментарии • 114

  • @vatsalanand9417
    @vatsalanand9417 4 года назад +3

    Your videos are of great help and the language you use is so simple and understandable.Thanks.

  • @farazromani
    @farazromani 7 лет назад +8

    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!

  • @TechTanka
    @TechTanka 7 лет назад +3

    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 лет назад +5

      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

  • @sergiojimenez3445
    @sergiojimenez3445 7 лет назад +56

    I came here looking for cooper and I found gold

  • @anweshvalleshetti3499
    @anweshvalleshetti3499 6 лет назад +16

    It throws nullpointer exception in the even case, because p is already null and your trying to access p.next()

    • @avinashkhetri9575
      @avinashkhetri9575 5 лет назад +6

      yeah, just reverse the order of the if conditions though

    • @AshishShukla-ro8oy
      @AshishShukla-ro8oy 5 лет назад +1

      Yeah just put if(!p.null && p.next=null) it will work

    • @ezrahn
      @ezrahn 5 лет назад +5

      Just check for the even condition first, and then the odd.

  • @ProgrammingTutorials1M
    @ProgrammingTutorials1M 5 лет назад +1

    We can also use stack to determine whether it's a palindrome or not.

  • @VanTran-zf7mg
    @VanTran-zf7mg 4 года назад +2

    Would you please make an example of copy constructor in the Linked List in C++? Thanks

  • @rishabhsahu5257
    @rishabhsahu5257 4 года назад +1

    Amazing !!Effort for us .Huge respect bro

  • @pankushmahajan4598
    @pankushmahajan4598 6 лет назад +8

    Mr. Vivekananda ji , try to make videos on hashing

  • @uzairkhurshid3036
    @uzairkhurshid3036 7 лет назад +1

    seriously dude this is really good .appreciate it

  • @satvikkhare1844
    @satvikkhare1844 2 года назад

    This was asked in my Nvidia experienced software interview. Please make more videos.

    • @SK-qn5ry
      @SK-qn5ry 2 года назад

      Oh nvidia, great

  • @ProgrammingArena
    @ProgrammingArena 6 лет назад +5

    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...

  • @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 ?

  • @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

  • @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..

  • @koeber99
    @koeber99 7 лет назад +1

    Or you could add all the elements to stack and then check half the LinkedList: time is O(n).... but space is O(n)

  • @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?

  • @informative_idiot-x6e
    @informative_idiot-x6e 6 лет назад +1

    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

  • @mdanishossain026
    @mdanishossain026 2 года назад

    sir , can you make please ad_hoc algorithm playlist

  • @palagatideepthireddy3659
    @palagatideepthireddy3659 6 лет назад +1

    in even linked list if p is nul lthe statement p->next will give segmentation fault because pointer pointing to non existing locaton

  • @alifruslan2728
    @alifruslan2728 4 года назад +2

    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 года назад +3

      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.

  • @shwetayadav3288
    @shwetayadav3288 4 года назад

    Very clear explanation.

  • @viewgood
    @viewgood 4 года назад +1

    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

  • @devotion_surya3741
    @devotion_surya3741 4 года назад

    Sir, what an explanation, amazing💥

  • @r3fl3xplays36
    @r3fl3xplays36 6 лет назад +2

    sir could you please make a video on XOR linked list , SKIP list , UNROLLED list..

  • @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).

  • @mohammedsadiq1567
    @mohammedsadiq1567 4 года назад

    Why not reverse the list first??
    And then compare?

  • @shailbenq
    @shailbenq 6 лет назад +2

    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 :)

  • @AddieInGermany
    @AddieInGermany 7 лет назад

    Sir please discuss how to recursion and when and where ? Especially with linked list, tree etc

  • @rajatbais6388
    @rajatbais6388 5 лет назад +1

    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.

  • @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 .

  • @GeekXpert
    @GeekXpert 5 лет назад +2

    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

  • @divyagupta5195
    @divyagupta5195 4 года назад

    how will this work for a b c c b ?

  • @rohan5713
    @rohan5713 6 лет назад

    but we also use the reverse of linked list approach also
    while(i

  • @prashantshukla7203
    @prashantshukla7203 7 лет назад

    you are doing great job sir!!

  • @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 !!!

  • @shloch2007
    @shloch2007 5 лет назад +3

    very good with explanations..........always checkout this channel, dope

  • @chetanshrivastava3762
    @chetanshrivastava3762 3 года назад

    Nice video.God bless you..

  • @sallyzhangt
    @sallyzhangt 6 лет назад

    Thank you. This is very clear.

  • @parambharti7095
    @parambharti7095 5 лет назад

    Very nice explanation.

  • @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

  • @ArpitDhamija
    @ArpitDhamija 4 года назад

    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

  • @hibritto
    @hibritto 2 года назад

    Genius.

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 2 года назад

    NICE SUPER EXCELLENT MOTIVATED

  • @gurpeetsingh9152
    @gurpeetsingh9152 6 лет назад

    sir can u provide a link to a source code...i am unable to find it

  • @ShivaniSingh-mq4pv
    @ShivaniSingh-mq4pv 3 года назад +1

    Amazing vedio

  • @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.

  • @pkl520
    @pkl520 7 лет назад

    explain very clear! Big thanks!

  • @ZeeshanKhan-mo9mu
    @ZeeshanKhan-mo9mu 7 лет назад

    plzz give me a function that check linked list is sorted or not? plzz give me code

  • @ridimamittal4064
    @ridimamittal4064 4 года назад

    amazing explanation , thank you so much :)

  • @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

  • @VishalYadav-ss4qv
    @VishalYadav-ss4qv 4 года назад

    Excellent 🙏🙏

  • @ghoshdipan
    @ghoshdipan 4 года назад

    This approch is ok but is not correct for all cases

  • @deepakborah8335
    @deepakborah8335 7 лет назад

    Really your videos are excellent

  • @srafayal
    @srafayal Год назад

    big an sir love you from odisha❤❤❤❤

  • @16avnisharma
    @16avnisharma 7 лет назад

    very useful videos.. keep posting sir

  • @bhavyanayyer3391
    @bhavyanayyer3391 3 года назад

    sir pls provide with the code???? not available on github

  • @shaikshabbir4479
    @shaikshabbir4479 7 лет назад

    Nice video sir. One query ? Does it work for string "aba" ?

  • @sushmitanigam4979
    @sushmitanigam4979 7 лет назад

    awesome explanation. Thanx a lot sir.

  • @ayoubaoumrani3200
    @ayoubaoumrani3200 10 месяцев назад

    Thank you sir

  • @jeezradz
    @jeezradz 4 года назад

    great video!!!

  • @vivekgr3001
    @vivekgr3001 4 года назад

    Amazing!

  • @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

  • @HarshaVardhan-jf9sd
    @HarshaVardhan-jf9sd 5 лет назад +2

    there is a bug in the algo

  • @vaibesb4u
    @vaibesb4u 7 лет назад

    Thank you sir. Very useful video

  • @pawanbasu6777
    @pawanbasu6777 6 лет назад

    didn't find the program in github!

    • @hardikrana2210
      @hardikrana2210 6 лет назад

      check this: github.com/vivekanand44/codes-RUclips-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp

  • @webTVfiction
    @webTVfiction 6 лет назад

    thank you brother

  • @kapztcs
    @kapztcs 4 года назад

    This is flawed , try to run the code against 1-2-1-2-1-2-1

  • @gurmeetchawla8362
    @gurmeetchawla8362 6 лет назад

    please put the lilnk to github

    • @hardikrana2210
      @hardikrana2210 6 лет назад

      github.com/vivekanand44/codes-RUclips-videos

  • @AddieInGermany
    @AddieInGermany 7 лет назад

    Perfect explanation sir. Thanks :)

  • @aka_gym_lad
    @aka_gym_lad 4 года назад

    sir tree ke question v dalo

  • @ashishsinha8893
    @ashishsinha8893 7 лет назад

    hello brother plz share github link

  • @md.abdullahal-alamin8059
    @md.abdullahal-alamin8059 7 лет назад

    thanks

  • @ashishsinha8893
    @ashishsinha8893 7 лет назад

    ye bro can you make the videos on bucket sort plZ

  • @imaneorj512
    @imaneorj512 Год назад

    Thanks ❤you save me

  • @saranyasaravanan7780
    @saranyasaravanan7780 7 лет назад +1

    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 лет назад +2

      github.com/vivekanand44/codes-RUclips-videos/blob/master/check%20if%20a%20string%20is%20a%20palindrome.cpp

    • @saranyasaravanan7780
      @saranyasaravanan7780 7 лет назад

      Thank u so much sir..