Question: Given an array contain 0s and 1s, sort the array such that all the 0s come before 1s. //Sorts a given list by selection sort
Given an array contain 0’s and 1’s, sort the array such that all the 0’s come before 1’s.![//Sorts a given list by selection sort //Input: An array A[0..n-1] of](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1708/9/2/6/93765dc27d99b0a81708926936444.jpg)
//Sorts a given list by selection sort //Input: An array A[0..n-1] of orderable elements. //Output: List A[0..n-1] sorted in ascending order Algorithm Selection Sort (A[ 0..n-1]) for i = to n - 2 do min = i for j =i + 1 to n - 1 do if A[j] A[min] min = j swap A[i] and A[min]
Step by Step Solution
3.29 Rating (149 Votes )
There are 3 Steps involved in it
1 Two Pointers Approach This method uses two pointers left points to the current element in the arra... View full answer
Get step-by-step solutions from verified subject matter experts
