Re: [algogeeks] Re: subsorted array

2010-12-21 Thread mohit ranjan
@Bhupendra Thanks for pointing it out actually, it should be 3.now first element in A[0]..A[j-1] greater than min is 7(index 1) and *LAST * element in A[k+1]A[n] less than max is 1(index 9) if you look at code, it was proper for( i = e+1; i < n; i++) { if(arr[i] < max) e = i;

[algogeeks] Re: subsorted array

2010-12-20 Thread nitdgp
@Snehal - Please avoid posting problems that have been solved somewhere else already. That decreases the value of this group. More people will be active here if we see new problems. Hope you get the point, no offence intended. -Swapnil -- You received this message because you are subscribed to

[algogeeks] Re: subsorted array

2010-12-20 Thread SVIX
simple and nice! n log n time... I however believe there's a way to get the solution in O(n) time... On Dec 19, 6:45 am, Ankur Khurana wrote: > how about sorting the array in an auxillary array first. then  compare > the elements in sorted and un sorted array. the first elements to > differ from

Re: [algogeeks] Re: subsorted array

2010-12-20 Thread bhupendra dubey
@mohit suppose the input array is {4,7,8,6,5,11,13,17,0,1,2,3} 1.first step of Ur algorithm gives j=2,k=9 (index of 8 and 1) 2.in the second step min and max comes out to be 5 and 13 3.now first element in A[0]..A[j-1] greater than min is 7(index 1) and first element in A[k+1]A[n] less tha

[algogeeks] Re: subsorted array

2010-12-19 Thread awesomeandroid
i have posted this problem along with solution to my blog check : http://code-forum.blogspot.com/2010/12/find-minimum-length-unsorted-subarray.html On Dec 18, 10:57 pm, snehal jain wrote: > Given an unsorted array arr[0..n-1] of size n, find the minimum length > subarray arr[s..e] such that sorti

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread mohit ranjan
@Snehal you can find example here http://geeksforgeeks.org/?p=8858 hope this will clear things for all :) Mohit On Sun, Dec 19, 2010 at 8:42 PM, snehal jain wrote: > @mohit > can u plz explain ur algo with an example > > On Sun, Dec 19, 2010 at 8:15 PM, Ankur Khurana > wrote: > >> how abou

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread mohit ranjan
@Ankur Murarka didn't get you, how you got time complexity as exponential, it's linear only. Mohit On Sun, Dec 19, 2010 at 8:15 PM, Ankur Khurana wrote: > how about sorting the array in an auxillary array first. then compare > the elements in sorted and un sorted array. the first elements to

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread snehal jain
@mohit can u plz explain ur algo with an example On Sun, Dec 19, 2010 at 8:15 PM, Ankur Khurana wrote: > how about sorting the array in an auxillary array first. then compare > the elements in sorted and un sorted array. the first elements to > differ from start and end in unsorted array constit

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread Ankur Khurana
how about sorting the array in an auxillary array first. then compare the elements in sorted and un sorted array. the first elements to differ from start and end in unsorted array constitute the sub array we are finding. i dont know this solution seems to easy , it might be wrong. Any comments ?

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread Ankur Murarka
Doesnt the time complexity seem to be a li'l large?? Looks like its taking exponential time... On Sun, Dec 19, 2010 at 5:01 PM, mohit ranjan wrote: > > Let A[0..n] be the array > > > Step 1: Start from A[0] and find out the first element, beyond which array > in not sorted, let's call it A[j] > S

Re: [algogeeks] Re: subsorted array

2010-12-19 Thread mohit ranjan
Let A[0..n] be the array Step 1: Start from A[0] and find out the first element, beyond which array in not sorted, let's call it A[j] Step 2: Start from A[n], move backward and find first element beyond which array in not sorted, let's call it A[k] so we have A[0]A[j].A[k]A[n] --

[algogeeks] Re: subsorted array

2010-12-18 Thread Dan
On Dec 18, 9:57 am, snehal jain 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. Sounds like a simple homework problem to me.:-) -- You received this message beca