How to find middle node in a Singly Linked List in Java? | Data Structures and Algorithms

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • ►Full DSA Course - • Data Structures and Al...
    ►Follow me on Instagram - bit.ly/intrvwk...
    ►Follow me on LinkedIn - bit.ly/fllwlkdn
    ►Enroll in the complete course: bit.ly/3W4qthg
    ►Source Code - github.com/din...
    ►Download DSA Animation Slides - techready.in/c...
    ►Click here to subscribe - www.youtube.co...
    Watch all my playlist here:
    ►Data Structures and Algorithms Course playlist: • Data Structures and Al...
    ►Mastering JUnit 5 - www.youtube.co...
    ►Mastering Mockito 3 - • Mockito 3 Tutorials
    ►Analysis of Algorithms - • Analysis of Algorithms
    ►Linked List Data Structures - • Linked List Data Struc...
    ►Array Data Structures - • Playlist
    ►Stack Data Structure - • Stack Data Structure
    ►Queue Data Structure - • Queue Data Structure
    ►Binary Tree Data Structure - • Binary Tree Data Struc...
    ►Graph Data Structure - • Graph Data Structure
    ►Binary Heap Data Structure - • Binary Heap Data Struc...
    ►Trie Data Structure - • Trie Data Structure
    ►Dynamic Programming Algorithms - • Dynamic Programming Al...
    ►Hashing Data Structures - • Hashing Data Structures
    ►Sorting and Searching - • Sorting and Searching
    ►String Algorithms - • String Algorithms
    Want to land a software engineering job in the IT industry? This course - 'Visualizing Data Structures and Algorithms' is here to help. The course walks you through multiple Java algorithms, data structures problems, and their solutions with step by step visualizations, so that you are actually learning instead of blindly memorizing solutions.
    The course covers in and outs of Data Structures and Algorithms in Java. Java is used as the programming language in the course. Students familiar with Javascript, Python, C#, C++, C, etc will also get to learn concepts without any difficulty. The implementation of various Algorithms and Data Structures have been demonstrated and implemented through animated slides. It covers many interview room questions on Algorithms and Data Structures. The questions and solutions are demonstrated by -
    1. Animated slide. (To make visualization of algorithms faster)
    2. Coding algorithm on IDE.
    The course covers topics such as -
    0. Algorithm Analysis
    1. Arrays
    2. Matrix
    3. Singly Linked List
    4. Doubly Linked List
    5. Circular Singly Linked List
    6. Stacks
    7. Queues
    8. Binary Tree
    9. Binary Search Tree
    10. Graphs
    11. Priority Queues and Heaps
    12. Recursion
    13. Searching
    14. Sorting
    15. Strings
    16. Trie Data Structure
    17. Dynamic Programming
    and many more ...
    #dsa #algorithms #coding

КОМЕНТАРІ • 59

  • @itsdineshvaryani
    @itsdineshvaryani  3 роки тому +1

    Please *Like* , *Comment* , *Share* , *Subscribe* and *Click Bell* 🔔🔔🔔 Icon for More Updates. To get *Data Structures and Algorithms* complete course for free please follow this link - ua-cam.com/play/PL6Zs6LgrJj3tDXv8a_elC6eT_4R5gfX4d.html

  • @shubhamagarwal1434
    @shubhamagarwal1434 2 роки тому +2

    Best series for DS & Algo. I am also 10 yrs java exp guy. Was looking for DS & Algo free course over UA-cam with java implementation and found this. Hats Off To You Man...Excellent Work. GOD BLESS YOU :)

  • @sathishkumarr7106
    @sathishkumarr7106 2 роки тому +3

    It the list contains only one node then. It will throw null pointer exception sir. Other than that Algorithm is really good. I love it, slow pointer works at 1X speed and fast pointer works as 2X speed. Once 2x traversed at end 1X will be in middle at the time. Superb!!!

  • @rohitvadhya7153
    @rohitvadhya7153 3 роки тому +2

    You also have to tell the middle node for number of nodes if there are 1 or 2.
    (1) if there is only one node in List then it will return the same node as middle node.
    (2) if there are 2 nodes in List then it will return the second node as middle node.

  • @ricardohernandezmendez4207
    @ricardohernandezmendez4207 3 місяці тому

    Great explanation. Thank you!

  • @abhisheksoni5177
    @abhisheksoni5177 5 років тому +1

    explanationation is extremly nunbelievable wow ......well explained

  • @AshishBurnwal
    @AshishBurnwal 6 років тому +1

    Awesome explanation. Thanks

  • @chandhu9916
    @chandhu9916 Рік тому

    Great explanation sir!
    The first ever video that i have commented!!
    Thank you!!!

  • @mnaatnhnui
    @mnaatnhnui 3 роки тому +1

    Thanks for this information..

  • @ahrazathar
    @ahrazathar 2 роки тому

    This Algorithm is good..
    For finding the middle node..

  • @roshnisingh7364
    @roshnisingh7364 6 років тому +1

    good explaination

  • @vasudevparmar9876
    @vasudevparmar9876 3 роки тому +3

    This code is absolutely right for 4 and 5 nodes
    But what if we want more than 20 nodes
    I think it will fail to give us middle node
    Please reply

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      It will give respective middle node !!!

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      The linked list you see in slide is for explaining how code will work on it. It will work on any number of nodes.

    • @vasudevparmar9876
      @vasudevparmar9876 3 роки тому +1

      @@itsdineshvaryani yeah it worked .
      thanks a lot

  • @yogeshbhatt4907
    @yogeshbhatt4907 2 роки тому +1

    Lot of learning sir, but which software you use and recommend ?

  • @vishnukar4520
    @vishnukar4520 2 роки тому +1

    Sir Your content is awesome!!! but sir just one thing can you please show the implementation in separate programs ...!

    • @itsdineshvaryani
      @itsdineshvaryani  2 роки тому

      you mean in separate video ???

    • @vishnukar4520
      @vishnukar4520 2 роки тому

      @@itsdineshvaryani No sir it feels little confusing when insertion deletion and all the etc etc code written in one single program. Just commenting it out makes it conjusted!!!!

    • @sujanraju5744
      @sujanraju5744 2 роки тому

      @@vishnukar4520 those are individual methods that isn't a problem.

  • @SubhashPavuskarhackzleo
    @SubhashPavuskarhackzleo 6 років тому +4

    consider we have 13 node. then middle of node will be 7th node, so in that case above logic will fail right ?

    • @pratapjavasingh3239
      @pratapjavasingh3239 3 роки тому +1

      Then count the first linked list length the u can find the middle of then no matters it's odd or even length elements

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      Yes its one way !!!

  • @kurlapallimaheswari5070
    @kurlapallimaheswari5070 Рік тому +1

    thank you sir!!!

  • @jaishukla5760
    @jaishukla5760 9 місяців тому

    Sir this is 57 lecture and i comple in 3 days ..💪💪

  • @razvanr4627
    @razvanr4627 5 років тому +3

    The explanation is very good but for some reason, when trying to run the method, a java.lang.NullPointerException is thrown.

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому +2

      I have added source code github link in description of video. Please check !!!

    • @pratapjavasingh3239
      @pratapjavasingh3239 3 роки тому

      Insertion logic little bit modification required otherwise u will get null pointer exception 😂

  • @prabhatsingh7391
    @prabhatsingh7391 3 роки тому

    in case of even suppose x and x+1 is the middle node,but on execution always x+1 is my output..how to deal with it.

  • @VivekYadav-rc2hv
    @VivekYadav-rc2hv 2 роки тому +1

    hello sir ,
    ListNode middle = s11.middleone();
    what the above precedure is called? is it dynamic binding.....kindly explain sir plzzzzzzzzzzzzzzz

    • @itsdineshvaryani
      @itsdineshvaryani  2 роки тому

      @vivek... i feel you first understand basic syntax and terminologies for Java ... you first learn those and after that watch this series !!!

  • @shashankvishwakarma959
    @shashankvishwakarma959 3 роки тому +1

    nice video !!

  • @johnrobert6471
    @johnrobert6471 6 років тому +1

    good

  • @amarchoubey5615
    @amarchoubey5615 3 роки тому +1

    Nice

  • @beldarshubham2463
    @beldarshubham2463 3 роки тому +1

    hey sir why you write return type as Listnode??

    • @Unknown-Stranger
      @Unknown-Stranger 3 роки тому +1

      coz u return middle node which of ListNode type

  • @ahrazathar
    @ahrazathar 2 роки тому

    Find length.
    If length is odd then middle node=(length+1)/2,
    If length is even then middle node=(length)/2 and (length)/2 +1..
    Break the loop once you find the middle node.I think O(n) will be approx 1.5 times than the above code..

  • @venkteshwarsahu1137
    @venkteshwarsahu1137 9 місяців тому

    if the list contain 2 elements then it will gives an error.

  • @tannubajpai4782
    @tannubajpai4782 3 роки тому

    Hello Sir can u help write code for taking out permutation in single step.

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому +1

      Didnt get u !!! You want any specific video on permutation ???

    • @tannubajpai4782
      @tannubajpai4782 3 роки тому

      @@itsdineshvaryani in my paytm interview I have explained him with recursive. But he want in single step

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      @@tannubajpai4782 can u tell me exact question he asked ??? Was it related to this video only ...

    • @tannubajpai4782
      @tannubajpai4782 3 роки тому +1

      @@itsdineshvaryani no it's not related to video. U explaination awsm. I thought u can help me.
      Question: to find permutation of string in single step?

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому +1

      Does single step means single line ... If yes please check this link ...stackoverflow.com/questions/56551982/one-line-java-string-random-permutation