Cyclic Sort

In this blog post, I will be giving a brief description about another important pattern for technical interviews. This pattern is called Cyclic Sort.

This pattern is very useful for solving problems that involves arrays containing numbers in a given range or finding duplicates or missing numbers. In this pattern, we iterate over the given array one number at a time. If the current number that we are iterating is not at the correct index then we swap it with the number at its correct index.

source: hackernoon.com

Identification of this pattern:

This pattern can be identified by following ways;

  1. If the problem involves with a sorted array in a given range,
  2. If the problem involves finding the missing or duplicate number in a sorted or rotated array.

References:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store