Excuse can you write a table of my code as this about all basic steps?
https://www.dropbox.com/s/8a77ho6vvwpn7zu/Passi%20base.jpg?dl=0
In some notes given by the professor I read""The calculation of asymptotic complexity is defined by the block of major complexity"
So for example 2n^2+2n+2 has asymptotic omplexity n^2 , you are agree?
And I don't understand well why
"Θ(n²) behavior, which means that it is also Ω(n²) and O(n²)."
Why n^2 for all, really I don't understand....
Here I read this abot what happens in selection sort
1 2 3 4 5 6
|
8 5 7 1 9 3 // (n-1) first smallest
1 5 7 8 9 3 // (n-2) second smallest
1 3 7 8 9 5 // (n-3) third smallest
1 3 5 8 9 7 // 2
1 3 5 7 9 8 // 1
1 3 5 7 8 9 // 0
|
total comparison= n(n-1)/2 ~ O(n^2)
But I don't understand also here and why n(n-1)/2 and ~ O(n^2)
Also I read:
"
In selection sort outer for loop execute n-1 times.
INvoke swap function once at ech iteration
Total swap=n-1
Total moves 3*(n-1) (each swap has three moves)
Th inner loop executes the size of unsorted part minus 1 (from 1 to n-1) and in each iteration we make one comparition
#of key comparition 1+2+...n-1= n*(n-1)/2
"
Why n*(n-1) 2????????
And why the best , average and worst case are the same and are all O(n^2)???