Skip to content

Conversation

simran-kaur5
Copy link

@simran-kaur5 simran-kaur5 commented Jul 26, 2025

What does this PR do?

  • Adds a C++ program to compute the minimum number of swaps required to sort an array.
  • Implements a cycle detection approach to count swaps efficiently.
  • Includes comments and basic test in main() function.

Algorithm Used

  • Paired values with original indices
  • Sorted the pairs by value
  • Detected cycles to count minimum swaps needed

Sample Test Case

Input:
{6, 7, 8, 1, 2, 3, 9, 12}
Output:
3 (Minimum swaps)

@realstealthninja
Copy link
Collaborator

Please follow the pull request format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants