Bubble sort algorithm efficiency

124 views Asked by At

I would like to know how to determine the efficiency of my array sorting algorithm. After researching big O notation I learned that the time complexity is polynomial of O(n^2) since the algorithm consists of 2 loops. Also, the space complexity is of O(1). However, I don't understand how to determine the efficiency.

public static void sortAnimalsArray(Animal[] animals)
{
    for (int i = 0; i < animals.Length; i++)//move row wise
    {
        for (int j = i + 1; j < animals.Length; j++)//move column wise
        {
            //first sort rowwise and considering each row then sort column wise 
            if (animals[i].Pos.letterX > animals[j].Pos.letterX || (animals[i].Pos.letterX == animals[j].Pos.letterX && animals[i].Pos.letterY > animals[j].Pos.letterY))
            {
                var temp = animals[i];
                animals[i] = animals[j];
                animals[j] = temp;
            }
        }
    }
} 
0

There are 0 answers