Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

big-o-intro

Big-O introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

An orientation to the DSA track—Big-O, classic structures, graph/DP patterns, and C++ playground practice for interviews.

You need explicit complexity reasoning before scaling services or passing FAANG-style loops—brute force rarely survives review.

You will apply Big-O introduction in contexts like: API design reviews, capacity planning, and whiteboard interview loops.

Compile and run C++17 snippets in the playground (`int main`, `std::cout`); after each run, state time and space complexity before moving on. Also read the interview prep blocks; state Big-O aloud before and after you change the code.

After basic /python/intro or /cpp/intro syntax—ideally alongside /numpy/intro for array thinking; intensify before interview season.

Big-O notation describes how runtime or memory grows as input size n increases. We ignore constants and focus on dominant terms—same idea you glimpsed when comparing Python loops to NumPy vectorization.

Common complexities (slowest to fastest growth)

  • O(1) — constant: index into array
  • O(log n) — halving: binary search
  • O(n) — linear: single loop over n items
  • O(n log n) — efficient sorts, many divide-and-conquer algorithms
  • O(n²) — nested loops over n
  • O(2ⁿ) — exponential; brute-force subsets (avoid at large n)

Rules of thumb

  • Drop constants: O(3n) → O(n)
  • Keep dominant term: O(n² + n) → O(n²)
  • Different inputs? O(a + b) when two arrays of different sizes

Count operations

#include 

int main() {
    int n = 8;
    int ops = 0;
    for (int i = 0; i < n; ++i) ops++;           // O(n)
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) ops++;       // O(n^2)
    std::cout << "ops ~ n + n^2 = " << ops << "\n";
    return 0;
}

Important interview questions and answers

  1. Q: Does Big-O measure exact seconds?
    A: No—it describes growth rate; hardware and constants still affect wall-clock time.
  2. Q: Best vs worst vs average?
    A: Interviews often mean worst-case unless stated; hash maps average O(1) with rare O(n) worst case.

Self-check

  1. Order O(1), O(n), O(n²) from fastest growing to slowest.
  2. Why drop the constant in O(3n)?

Tip: Drop constants and lower-order terms—interviewers want dominant growth.

Interview prep

Big-O purpose?

Describes growth rate as n increases; ignores constants.

Common orders?

O(1), O(log n), O(n), O(n log n), O(n²), exponential.

Average vs worst?

Clarify which case—hash map average O(1), worst O(n) with collisions.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • O(n) example?
  • Ignore constants?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump