Why is this the best and worst case of this algorithm?

Algorithm Non_DC(A,n,max,min)
{
    max<-min<-A[1 ];
    for i<-2 to n 
    {
        if(A[i]>max)
        {
            max<-A[i];
        }
        else if (A[i]<min)
        {
            min<-A[i];
        }
    }
}

It’s said that the best case of this algorithm is if array is in increasing order. Why?
It’s said that the worst case of this algorithm is if array is in decreasing order. Why?
I know this is probably a dumb question, but I am failing to understand this much as well.

Hi

From what I see this pseudocode algorithm iterates through an array to find and display the min and max values of said array.

Without context my guess is that an array in an ascending order means a positive outcome, while a decreasing order is alarming, “worst case”.

With no context provided it’s pure speculation though.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.