TomoLink
TCS NQT GuideTCS NQT Programming Logic & CS FundamentalsTime and Space Complexity (Big O Notation) Simplified

Time and Space Complexity (Big O Notation) Simplified

Learn core concepts, essential formulas, and attempt practice questions designed on the latest TCS NQT testing patterns.

Key Concepts & Formulas

  • 1Big O: Upper bound of execution time/space growth.
  • 2Single loop: O(N). Nested loop: O(N^2).
  • 3Binary Search: O(log N). Quick Sort (Average): O(N log N).

TCS NQT Style Practice Questions

Practice Question 1

What is time complexity of searching in a sorted array using Binary Search?

A) O(log N)
B) O(N)
C) O(N log N)
D) O(1)

Correct Answer: A) O(log N)

Step-by-step Solution: Binary Search halves the search space in each step, leading to logarithmic O(log N) time complexity.

Practice Question 2

What is time complexity of: for(int i=0; i<n; i++) for(int j=0; j<n; j++) print("*");?

A) O(N^2)
B) O(N)
C) O(N log N)
D) O(2^N)

Correct Answer: A) O(N^2)

Step-by-step Solution: An outer loop running N times wraps an inner loop running N times. Total operations = N * N = N^2.

Study Pro-Tip

Avoid assuming complexity from loop counts. Always analyze how variables decrement/increment.