Neoalgo: Graph Problem:-Minimum Number of Swaps Required to Sort an Array

Created on 16 Aug 2020  路  10Comments  路  Source: TesseractCoding/NeoAlgo

馃殌 Feature

You are given an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. You are allowed to swap any two elements. You need to find the minimum number of swaps required to sort the array in ascending order.

Have you read the Contributing Guidelines on Pull Requests?

YES

Motivation

As it has not beed added in any issue in hakin-codes.

Pitch

Very Common Algorithm. It is Useful in Solving Many Graph related Problems.

C C-Plus-Plus CH20 Java Python medium no-issue-activity

Most helpful comment

@Kajol-Kumari @SKAUL05 @Abhijit2505 @plazzy99 @siddharth25pandey
Can you please add the relevant labels to it and assign the issue to me. Thank you!

All 10 comments

@Kajol-Kumari @SKAUL05 @Abhijit2505 @plazzy99 @siddharth25pandey
Can you please add the relevant labels to it and assign the issue to me. Thank you!

Hey @DrSehgal7 can you please mention the language you are going to do it?

@Kajol-Kumari Would like to work on C++ and C both

I would like to work on this in Python

I would like to work on this in Java.

@ritvij14 go with java

@DrSehgal7 I had a doubt about this algorithm. Is the array consisting of any set of consecutive integers that are arranged unordered? Or is it like the first N consecutive integers from 1 to N?

@ritvij14 For example N= 50 so you will have an array of 50 elements and all of them will be from 1 to 50 without duplicates.
For eg:-
N=10
array[]={3 7 6 9 1 8 10 4 2 5}
ans=9

I hope your doubt is clear now!

@DrSehgal7 yes it's clear now, thanks for the clarification. :D

Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Telegram or ping one of the reviewers. Thank you for your contributions!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahanabalappa picture sahanabalappa  路  8Comments

keshav304 picture keshav304  路  7Comments

HarshCasper picture HarshCasper  路  8Comments

Joshitha18 picture Joshitha18  路  10Comments

HarshCasper picture HarshCasper  路  11Comments