Comb Sort Algorithm Intro: Comb Sort is an Improved version of Bubble Sort. The basic plan is to eliminate turtles, or tiny values close to the end of the list, since in a very bubble kind these slow the sorting down tremendously. Rabbits, massive values round the starting of the list, don’t cause a haul in bubble kind. In bubble kind, once any 2 parts are compared, they continually have a spot (distance from every other) of one. the essential plan of comb kind is that the gap is often way more than one.

Bubble sort continuously compares adjacent values. therefore all inversions are removed one by one. Comb sort improves on Bubble sort by using the gap of size more than one. The gap starts with an outsized value and shrinks by an element of one.3 in each iteration till it reaches the worth one. therefore Comb sort removes more than one inversion counts with one swap and performs much better than Bubble sort.

Comb Sort Algorithm Pseudo Code:

function combsort(array input)

    gap := input.size // Initialize gap size
    shrink := 1.3 // Set the gap shrink factor
    sorted := false

    loop while sorted = false
        // Update the gap value for a next comb
        gap := floor(gap / shrink)
        if gap > 1
            sorted := false // We are never sorted as long as gap > 1
        else
            gap := 1
            sorted := true // If there are no swaps this pass, we are done
        end if

        // A single "comb" over the input list
        i := 0
        loop while i + gap < input.size // See Shell sort for a similar idea
            if input[i] > input[i+gap]
                swap(input[i], input[i+gap])
                sorted := false
                // If this assignment never happens within the loop,
                // then there have been no swaps and the list is sorted.
             end if

             i := i + 1
         end loop

     end loop
 end function