Cycle Sort || Java + DSA course || Blog 14

W e learnt about Sorting algorithms like bubble sort, insertion sort, selection sort in Blog 9 Sorting in Java . So why are we learning cycle sort in a new blog? Cycle sort questions are asked in various tech interviews , in huge companies like Facebook , Amazon , Google ... For a quick overview, we will be learning:- W hat is C yclic sort ? How to solve Code Working of the code. What is cyclic sort? Cyclic sort is used on an array from 1 to n or from 0 to n. In 1 to n case, we know that our first value will be 1 followed by 2 3 4...n. if we try to place it at index 0(in java, index of an array starts from 0) we know value is 1 which can be also said as index+1 = 0+1 = 1. At index 1, 2 should be placed = index+1 = 1+1 = 2. This should keep on happening till nth value becomes n+1. If we want a formula for index, it is index = value - 1 since every value has index+1 index. How to solve Lets take array = {3,5,1,2,4} Correct index value should be arr[i]-1 We will check if our ...