Complexity
Complexity
appropriate.
The point:
1. Original set up: O(N*log(N)) for both (building BST and sorting an originally unsorted
array)
2. Later insertions: O(log(N)) for BST vs O(N) for insertion sort in array of O(N*log(N)) for
resorting (both worse than BST).
Solution:
Out runs n times and i increases by one each time. So this results in the inner loop running
1+2+3+4+....+(n-1)= n(n+1)/2= O(n^2).