Тёмный

Minimum Swaps Required to Sort an Array 

DS Algo
Подписаться 1 тыс.
Просмотров 90 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 32   
@DSAlgo
@DSAlgo 4 года назад
Minimum Swaps Required to Sort an Array [Non-Consecutive Distinct Integers] : ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8XuaJwQ2P5k.html
@PradeepKumar-ue2ct
@PradeepKumar-ue2ct 4 года назад
Can you please mention time complexity of this solution?
@DSAlgo
@DSAlgo 4 года назад
Time complexity to find the minimum swaps is mentioned below: i. Using Efficient algorithm is O(n log(n)). ii. Using Selection sort algorithm is O(n^2).
@anandsehgal8845
@anandsehgal8845 4 года назад
Great!! You have Explained well and implemented optimal solution
@vikashpanchal9609
@vikashpanchal9609 4 года назад
Really very effective approach to reduce swap counts.the way of explaining is very good and understandable. Thankyou so much.
@deepaligarg2978
@deepaligarg2978 2 года назад
Thanks for the explanation.
@ardey7
@ardey7 4 года назад
Helpful and clear. Thanks !
@rengaisok
@rengaisok 4 года назад
I understand the logic can someone explain why this works?
@MaXxamillion00
@MaXxamillion00 4 года назад
This works this way because this case is somewhat unique: all elements in the array are unique, and once sorted, all element values match their corresponding indices.... as in 1 is in position 1, 2 will be in position 2, 4 in 4, etc. That is why you can find one element out of place(because index!=value) and immediately jump to the place it SHOULD BE (index==value), and do the same thing with the out-of-place element found there. Eventually you will find the element that belongs to the initial index you were checking, the first out-of-place element, and that whole series of elements becomes a "cycle", you can perform an exact finite series of swaps to get all of those elements into their corresponding indices... like the video describes haha but long story short it works this way because in this array, once sorted, index==element for all indices.
@purut5105
@purut5105 4 года назад
Nice Explanation!
@abhinavghosh725
@abhinavghosh725 4 года назад
this will only work for non duplicate values. nevertheless good work
@SudhanshuKumar-lp1nr
@SudhanshuKumar-lp1nr 3 года назад
yes it's always distinct elements
@kratikamaheshwari421
@kratikamaheshwari421 4 года назад
Thanxx.. I really enjoyed the way you explained the concept.
@ruchirsrivastava6808
@ruchirsrivastava6808 4 года назад
Very good explanation. Looking forward to more videos.
@kirtirai4502
@kirtirai4502 4 года назад
Your handwriting is so good
@AnkitSingh-gi5zw
@AnkitSingh-gi5zw 4 года назад
Awesome. Very nicely and clearly explained !!
@Anubis10110
@Anubis10110 4 года назад
The explanation is AWESOME but the code is broken. could you please check it
@DSAlgo
@DSAlgo 4 года назад
Thanks Mohamed, The code is working fine and code link is available in the description.
@Anubis10110
@Anubis10110 4 года назад
@@DSAlgo Thanks I will check it..It's appearing now.
@devidrsr
@devidrsr 4 года назад
Awesome, keep it up 👍😇
@akshatgupta7863
@akshatgupta7863 4 года назад
gr8 video!! make more videos for common problems
@shivammishrasvnit5456
@shivammishrasvnit5456 3 года назад
nice
@sumanth5087
@sumanth5087 4 года назад
Anyone have python code
@AnkitSharma-hk8yq
@AnkitSharma-hk8yq 4 года назад
We can use selection sort which always takes least no. of swappings to sort an array. In the given array selection sort will take 1 swapping only.
@DSAlgo
@DSAlgo 4 года назад
Thanks for suggestion, The selection sort algorithm is not an efficient solution for this problem. Please see the explanation below: The selection sort algorithm is a brute force approach i.e. more computational effort is required. Therefore, It is not an optimal solution for finding the minimum swaps required to sort an unordered array consisting of consecutive distinct integers ∈ [1,2,3,...n]. e.g. [4,3,2,1] [1,5,4,3,2] We can use the selection sort algorithm for unordered array consisting of distinct integers ∈ Z i.e. {..., -2, -1, 0, 1, 2, ...}. e.g. [2,4,1,5] [4, 10, 2, 1, 0] ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8XuaJwQ2P5k.html - Selection sort algorithm approach.
@aisakyunhotahai8130
@aisakyunhotahai8130 4 года назад
Your handwriting is awesome😁😂
@amitojsingh9373
@amitojsingh9373 4 года назад
pretty simple explanation
@garimapandey1006
@garimapandey1006 4 года назад
Nice Content with gud explanation 👍
Далее
10 FORBIDDEN Sorting Algorithms
9:41
Просмотров 904 тыс.
Nightmare | Update 0.31.0 Trailer | Standoff 2
01:14
Просмотров 584 тыс.
Rate our flexibility 1-10🔥👯‍♀️😈💖
00:12
Brawl Stars expliquez ça
00:11
Просмотров 6 млн
Array Rotation | Block Swap Algorithm
9:33
Просмотров 6 тыс.
Why the FASTEST Sorting Algorithm can(t) be O(N)!
9:41
Minimum swap required to Sort an Array
9:49
Просмотров 11 тыс.
Google Data Center 360° Tour
8:29
Просмотров 5 млн
How I Got Good at Coding Interviews
6:29
Просмотров 1,7 млн
Nightmare | Update 0.31.0 Trailer | Standoff 2
01:14
Просмотров 584 тыс.