[algogeeks] Re: Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted

2011-11-24 Thread vikas
char arr[] = {'a', 'b', 'e', 'f', 'd', 'g', 'h', 'i'};

calculate the point where array is not sorted , in this case arr[4] =
'd'
calulate k in array[5..n] such that k  4 arr[k]  d  , take the min =
min{ arr[k] }
same thing for max from reverse
use quick /selection sort to identify the correct insertion indices of
min/max, that will be answer.
complexity O(n)

On Nov 24, 2:06 pm, Ankuj Gupta ankuj2...@gmail.com wrote:
 Given an unsorted array arr[0..n-1] of size n, find the minimum length
 subarray arr[s..e] such that sorting this subarray makes the whole
 array sorted.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted

2011-11-24 Thread Nitin Garg
Struct tuple
{int s;int e;}

tuple findsubarray(Array input)
{
int i=0, j=input.length()-1;

while(input[i]  input[i+1])
i++;

if(i==j) return NULL // array already sorted

while(input[j-1]  input[j])
j--;

// now the subarrays from 0 to i is sorted and  j to end is sorted.

int min = min(input(i+1,j-1));
int max = max(input(i+1,j-1));

while(input[i]min  i0)
 i--;

while(input[j]max  jinput.size()-1)
j++;

return (i,j);
}


On Thu, Nov 24, 2011 at 6:09 PM, vikas vikas.rastogi2...@gmail.com wrote:

 char arr[] = {'a', 'b', 'e', 'f', 'd', 'g', 'h', 'i'};

 calculate the point where array is not sorted , in this case arr[4] =
 'd'
 calulate k in array[5..n] such that k  4 arr[k]  d  , take the min =
 min{ arr[k] }
 same thing for max from reverse
 use quick /selection sort to identify the correct insertion indices of
 min/max, that will be answer.
 complexity O(n)

 On Nov 24, 2:06 pm, Ankuj Gupta ankuj2...@gmail.com wrote:
  Given an unsorted array arr[0..n-1] of size n, find the minimum length
  subarray arr[s..e] such that sorting this subarray makes the whole
  array sorted.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Nitin Garg

Personality can open doors, but only Character can keep them open

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.