0
Optimised code for sorting
Hello I came across a question related to sorting... Array is of size 1 lacs and possible values are two only either 0 or 1. Can we sort an array with O(N)?
2 Answers
+ 1
Does the sorting has to be stable?
Just count the number of 1 and 0 and run another loop to set same no of 1's and 0's.
Space O(1) time O(n)
For integers take a look at radix sort and counting sort.