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

preview_player
Показать описание

Watch all my playlist here:

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
Рекомендации по теме
Комментарии
Автор

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

shubhamagarwal
Автор

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

sathishkumarr
Автор

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.

rohitvadhya
Автор

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

chandhu
Автор

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

yogeshbhatt
Автор

explanationation is extremly nunbelievable wow explained

abhisheksoni
Автор

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

SubhashPavuskarhackzleo
Автор

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

vishnukar
Автор

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

vasudevparmar
Автор

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.

prabhatsingh
Автор

hello sir,
ListNode middle = s11.middleone();

what the above precedure is called? is it dynamic explain sir

VivekYadav-rchv
Автор

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

jaishukla
Автор

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

ahrazathar
Автор

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

razvanr
Автор

hey sir why you write return type as Listnode??

beldarshubham
Автор

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

venkteshwarsahu
Автор

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

tannubajpai
Автор

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

ahrazathar