JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Cycle-Sort. Show all posts
Showing posts with label Cycle-Sort. Show all posts

what is Cycle Sort?

11:25 PM
Cycle Sort Cycle sort is a comparison sorting algorithm which forces array to be factored into the number of cycles where each of them can be rotated to produce a sorted array. It is theoretically optimal in the sense that it reduces the number of writes to the original array. Algorithm Consider an array of n distinct elements. An element a is given, index of a can be calculated by counting the number of elements that are smaller than a. if the element is found to be at its correct position, simply leave it as it is. Otherwise, find the correct position of  a  by counting the total number of elements that are less than  a . where it must be present in the sorted array. The other element b which is replaced is to be moved to its correct position. This process continues until we got an element at the original position of  a . The illustrated process constitutes a cycle. Repeating this cycle for each element of the list. The resulting list will be sorted. C program

.