@Kamakshii: Do a binary search on a[i] - a[i-1]. If this is negative,
i is in the decreasing range, i.e., i < k, so reset the lower limit of
the interval. If it is positive, i is in the increasing range, i.e., i
> k, so reset the upper limit of the interval. Quit when the interval
length is 1. Let k be the lower limit of that interval. Then a[k] -
a[k-1] < 0, so a is decreasing at k, and a[k+2] - a[k+1] > 0, so a is
increasing at k+1. According to the problem statement, it is possible
for a[k] to equal a[k+1]. In this case, a[0] to a[k] still is
decreasing and a[k+1] to a[n-1] still is increasing, so this value of
k works.

Dave

On Aug 4, 1:23 pm, Kamakshii Aggarwal <kamakshi...@gmail.com> wrote:
> @dave:how can we find value of 'k' in (log n)
>
> On Thu, Aug 4, 2011 at 5:41 PM, kartik sachan <kartik.sac...@gmail.com>wrote:
>
> > @amit it's given that array is increasing then decreasing..........so where
> > there is change from incre to drece that value of i in loop will be k
>
> > in this we can find out k if not given
>
> > --
> > 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.
>
> --
> Regards,
> Kamakshi
> kamakshi...@gmail.com

-- 
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.

Reply via email to