Campbell Ritchie wrote:I haven't got the time to watch those videos. But I looked at Wikipedia, which says that insertion sort is one of the more efficient types of sorting in quadratic time (n²). The bit about quadratic time means that the time taken is proportional to the square of the number of elements; it should take 4× as long to sort a 2,000,000‑element list as a 1,000,000‑element list. Note that is the worst case behaviour; you will occasionally be lucky and find lists requiring little sorting, and the process runs much faster.
Campbell Ritchie wrote:If you mean they calculate the timings with an² + bn + c, then a b c are “constants” and n the number of elements in question. When you are dealign with large numbers, say 1,000,000 or 2,000,000, if you square them you get 1.0×10¹² or 4.0×10¹² and that increase will overwhelm the change from n = 1,000,000 to n = 2,000,000. So the time complexity reduces to its worst (=highest exponent) term. Beware if you have the misfortune to get eⁿ (or xⁿ) complexity (=exponential complexity) where doubling the size of the task can cause its duration to square itself. You will find a naïve recursive approach to calculating Fibonacci numbers in many beginning books; that runs in exponential complexity, but its base is small: it uses (approx) 1.618‟ complexity.
Linden Garcia wrote:As you say n relates to the number of elements in question and the squared part represents the growth, but what is the point/function of the constants?
Complexity goes on the worst component of the formula, and the constants cancel out: an₀² ÷ an₁² reduces to n₀² ÷ n₁².Paul Clapham wrote:. . . there isn't any point. Constant values have no effect on the time complexity. . . .
Consider Paul's rocket mass heater. |