why we are making auxillary arrays and why we are adding 1 each time when array is increasing and finally why we are finding maximum value of inc[i]+dec[i]-1.
Maximum length biotonic problem
auxiliary arrays are made to store the previous answers we have already computed.
we are computing the maximum because we need to find the maximum length of the bitonic subarray
i think you have not understood the question. Go through the question once again and if you still donβt understand then you ask again here
-
Construct an auxiliary array inc[] from left to right such that inc[i] contains length of the nondecreaing subarray ending at arr[i].
For A[] = {12, 4, 78, 90, 45, 23}, inc[] is {1, 1, 2, 3, 1, 1} -
Construct another array dec[] from right to left such that dec[i] contains length of nonincreasing subarray starting at arr[i].
For A[] = {12, 4, 78, 90, 45, 23}, dec[] is {2, 1, 1, 3, 2, 1}. -
Once we have the inc[] and dec[] arrays, all we need to do is find the maximum value of (inc[i] + dec[i] β 1).
For {12, 4, 78, 90, 45, 23}, the max value of (inc[i] + dec[i] β 1) is 5 for i = 3.
i am still unable to understand the auxilary arrays how you are calculting
you can refer this https://ide.codingblocks.com/s/94146
dry run the logic then you will definately understand
i dry run on the above code it is perfect but can you tell me how you get the logic of max1=max(max1,inc[i]+dec[i]-1) pls can you explain it