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

Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants