178k views
3 votes
Sorting a sequence of N numbers by adding them successively to a list (finding and putting them into the proper location by value) has worst case time complexity of

a) O(N log N)
b) O(N²)
c) O(log N)
d) O(1)

User Kelgwiin
by
8.4k points

1 Answer

3 votes

Final answer:

The worst case time complexity of sorting a sequence of N numbers by successive insertion is O(N²), representing the sum of the first N natural numbers and dropping constants in Big O notation.

Step-by-step explanation:

The question asks about the worst case time complexity of sorting a sequence of N numbers by adding them successively to a list and finding the appropriate location for each number. This approach is analogous to the insertion sort algorithm. In the worst case, each new number may need to be compared to all the others already in the list before finding its proper place. As a result, for the first number there's 1 comparison, for the second number up to 2 comparisons, for the third up to 3, and so on, leading up to N comparisons for the last number. Adding these up gives us 1 + 2 + 3 + ... + (N-1) + N, which is the sum of the first N natural numbers, equating to N(N+1)/2. In Big O notation, we drop constants and lower order terms, resulting in a time complexity of O(N²).

User Gitter
by
8.1k points