Nested loops into mathematical model to count number of operations

后端 未结 4 477
野性不改
野性不改 2021-01-13 12:24

I\'m reading the book \'Algorithms - Fourth edition\' by Sedgewick and Wayne and I must admit that some parts in the \"Analysis of Algorithms\" chapter are confusing me! Thi

4条回答
  •  悲哀的现实
    2021-01-13 12:54

    As we know...

    1+2+3+4...+N => N(N-1)/2

    Similarly, the innermost loop works something like

    1.n+2(N-1)+3(N-2)+...N.1 => N(N-1)(N-2)/6

    Here is a proof for this.

提交回复
热议问题