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

**URL:** <https://forum.kirupa.com/t/why-is-this-the-best-and-worst-case-of-this-algorithm/663710>\
**Category:** Uncategorized\
**Created:** [December 16, 2023, 9:38am UTC](https://forum.kirupa.com/t/why-is-this-the-best-and-worst-case-of-this-algorithm/663710 "2023-12-16T09:38:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oslon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/oslon/32/24631_2.png) [@oslon](https://forum.kirupa.com/u/oslon)\
**Post date:** [December 16, 2023, 9:38am UTC](https://forum.kirupa.com/t/why-is-this-the-best-and-worst-case-of-this-algorithm/663710/1 "2023-12-16T09:38:50Z")

</div>

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