The complexity of method1
is O((log n)²) since we have a nested loop where each loop runs O(log n) times.
In Method2
we execute Method1
a triangluar number of times, i.e., we execute it O(n²) times. Since we execute an O((log n)²) function O(n²) times, the resulting complexity for Method2
is O(n² ⋅ (log n)²).