Selection Sort - Time Complextity

 


Time Complexity of Selection Sort








 Selection sort  is using two for loops to do one iteration. The first loop (Outer loop ) travels through an array starting from index 1, while the inner loop runs from index 1 to index i-1. The following diagram shows the Number of execution rounds it performs.




when i is 1, the inner for loop runs only one time. when i is 2, inner for loop runs 2 times. Likewise when i is   n   the inner for loop runs n times.


So the total number of Execution rounds can be calculated by adding all Execution times in each i values. 














  

Time Complexity       =    n (n+1)

                                        2

                                 =   n2 + n

                                      2     2


 since the determinant factor is square of n, time complexity depends on only the square of n.



                       F(n) = O (n2)






Comments

Popular posts from this blog

Insertion Sort - Time Complexity

Quick Sort - Time Complexity