No video

How to remove loop from a Singly Linked List? | Floyd Cycle Detection Algorithm | (Implementation)

  Рет қаралды 10,415

Dinesh Varyani

Dinesh Varyani

3 жыл бұрын

►Full DSA Course - • Data Structures and Al...
►Follow me on Instagram - bit.ly/intrvwkckstrt
►Follow me on LinkedIn - bit.ly/fllwlkdn
►Enroll in the complete course: bit.ly/3W4qthg
►Source Code - github.com/dinesh-varyani/ds-...
►Download DSA Animation Slides - techready.in/courses/150-dsa-...
►Click here to subscribe - kzfaq.info...
Watch all my playlist here:
►Data Structures and Algorithms Course playlist: • Data Structures and Al...
►Mastering JUnit 5 - kzfaq.info?list...
►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

Пікірлер: 44
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Please *Subscribe* and *Click Bell* 🔔🔔🔔 Icon for More Updates. To get *Data Structures and Algorithms* complete course for free please follow this link - kzfaq.info/sun/PL6Zs6LgrJj3tDXv8a_elC6eT_4R5gfX4d
@huzaifaimran9468
@huzaifaimran9468 3 жыл бұрын
Great video!!! But this method does not work if there is only 1 cycle in whole list at the start for example: to get around this we can use the start of loop method and check if slowPointer == startingPointer public void removeLoop() { //here nodes are = pointers //for single loop in whole list Node slowNode = detectLoop(); //returns slowPointer Node startingNode = detectStartOfLoop(); //returns the startingPointer if (slowNode == startingNode) // checking if slowNode = startingNode { while (slowNode.next!= startingNode) //looping until we have the last element of loop (before loop restarts) { slowNode = slowNode.next; } slowNode.next = null; return; } //for loop in a list with other values as well if (slowNode != null) { Node temp = head; while (temp.next != slowNode.next) { //getting the last element of loop before loop is restarted System.out.println(slowNode.data); temp = temp.next; slowNode = slowNode.next; } slowNode.next = null; //breaking the cycle before end and start of loop } }
@shubhamagarwal1434
@shubhamagarwal1434 2 жыл бұрын
Best series for DS & Algo. I am also 10 yrs java exp guy. Was looking for DS & Algo free course over KZfaq with java implementation and found this. Hats Off To You Man..Excellent Work. GOD BLESS YOU :)
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
Thanks !!!
@vyomgupta7523
@vyomgupta7523 Жыл бұрын
Hii sir
@travel2explore627
@travel2explore627 2 жыл бұрын
Really thankful for these videos 👍
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
Welcome !!!
@MANISHYADAV-dd4ug
@MANISHYADAV-dd4ug 3 жыл бұрын
❤️❤️
@saik14
@saik14 3 жыл бұрын
Good work!
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Thanks !!!
@sreddy8141
@sreddy8141 3 жыл бұрын
Thanks a lot for this wonderful series sir, Its really helpful. Kindly start series on programs based on these algo. Arrays, trees
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Its started !!!
@sreddy8141
@sreddy8141 3 жыл бұрын
@@itsdineshvaryani ua the best sir🙂🙏
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
@@sreddy8141 thanks !!! Keep supporting.
@Unknown-Stranger
@Unknown-Stranger 3 жыл бұрын
Guys if you are getting wrong output when loop starts from 1st node of the Linked List, following code will cover this edge case(second removeLoop(slowPtr) method name I changed to makeLastNodeNull(slowPtr). : public void makeLastNodeNull(ListNode slowPtr) { ListNode temp = head; if(temp == slowPtr) { while(slowPtr.next != temp) { slowPtr = slowPtr.next; } slowPtr.next = null; return; } while(temp.next != slowPtr.next) { temp = temp.next; slowPtr = slowPtr.next; } slowPtr.next = null; }
@mayanksrkumar16
@mayanksrkumar16 Жыл бұрын
This worked! Thanks a lot!
@SatyamGupta-yq1pt
@SatyamGupta-yq1pt 3 жыл бұрын
amazing content
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Thanks !!!
@abhishekranjan1094
@abhishekranjan1094 3 жыл бұрын
Nice sir
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Thanks !!!
@jayasekharredditelluri1600
@jayasekharredditelluri1600 2 жыл бұрын
sir your not explaining any time and space complixities here why?
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
Will try to add !!!
@jagadeshreddyvankala6020
@jagadeshreddyvankala6020 2 жыл бұрын
i am not getting output after the code is growing longer
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
check source code in description
@divyanshumaheshwari1880
@divyanshumaheshwari1880 2 жыл бұрын
sir why u created private method for removeloop(ListNode slowptr) method
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
Extract logic out in diff method ...
@divyanshumaheshwari1880
@divyanshumaheshwari1880 2 жыл бұрын
@@itsdineshvaryani so we can use public method also to make it??
@jaspalsingh-mv5xh
@jaspalsingh-mv5xh 3 жыл бұрын
It give me the output : 1->2->3->4->5->null
@jaspalsingh-mv5xh
@jaspalsingh-mv5xh 3 жыл бұрын
It doesn't give me the 6th node
@ascar66
@ascar66 2 жыл бұрын
Sir why we have two methods with same name? I mean we have public void removeLoop(){} and private void removeLoop(ListNode slowPtr){}. Is it overloading of the method? The same method name with different signatures?
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
You can give a different name as well !!!
@dailybloggerr
@dailybloggerr Жыл бұрын
but in one method we are passing a argument so it treated as different
@vasudevparmar9876
@vasudevparmar9876 3 жыл бұрын
why did we name both function removeLoop
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
doesnt matter
@vasudevparmar9876
@vasudevparmar9876 3 жыл бұрын
@@itsdineshvaryani so isn't there any chances of recursive call?
@itsdineshvaryani
@itsdineshvaryani 3 жыл бұрын
Parameters are different in both methods ....
@vasudevparmar9876
@vasudevparmar9876 3 жыл бұрын
@@itsdineshvaryani this code fails when cycle starts from 1st node
@HariKrishnan-ks3dh
@HariKrishnan-ks3dh 3 жыл бұрын
@@vasudevparmar9876 if(temp == slowptr) { while(temp.next.next != slowptr.next) { temp = temp.next.next; slowptr = slowptr.next; if(temp.next.next == slowptr.next) { slowptr.next = null; } } } i solved the problem that if cycle occured in the head then it will be removed by this code
@jagadeshreddyvankala6020
@jagadeshreddyvankala6020 2 жыл бұрын
i am getting any output from here
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
check source code in description
@itsdineshvaryani
@itsdineshvaryani 2 жыл бұрын
check source code in description
How to find start of a loop in a Singly Linked List? (Animation)
12:45
Why Floyd's Cycle Detection algorithm works?
19:30
Dinesh Varyani
Рет қаралды 20 М.
UNO!
00:18
БРУНО
Рет қаралды 3,3 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Remove Loop from Linked List | C++ | Java | Python
15:58
Ayushi Sharma
Рет қаралды 9 М.
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 84 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
UNO!
00:18
БРУНО
Рет қаралды 3,3 МЛН