educative.io

Clarification on Calculating Running Time Complexity

Hi,

I understand that the inner loop runs [n(n - 1)] / 2 times. Thus, range(i) takes [n(n - 1)] / 2 steps, initializing j every time takes [n(n - 1)] / 2 steps, and furthermore, val += 1 takes 3 * [n(n - 1)] / 2 steps. So should not the running time complexity be

[n(n - 1)] / 2 + [n(n - 1)] / 2 + 3 * {[n(n - 1)] / 2} = 5 * [n(n - 1)] / 2 ?

Thank You,
Kowshik


Course: Data Structures for Coding Interviews in Python - Learn Interactively
Lesson: Complexity Quiz: Test your understanding of complexity - Data Structures for Coding Interviews in Python

Hi @Kowshik_Islam we can ignore the constant while computing time complexity.