Data Structures & Algorithms: Crack the Interview
Chapter 1 / 8· 20 min read· 0 cards

What is DSA and Why Big-O Decides Everything

Why DSA matters for interviews, and how to measure whether code is fast or slow.

Why DSA is the subject that gets you hired

If you want a job at a strong product company — or to clear campus placements — Data Structures and Algorithms is non-negotiable. Companies don't test whether you've memorised a framework; they test whether you can think. Given a problem, can you choose the right way to organise data (the data structure) and the right set of steps to solve it (the algorithm)? That's what DSA trains, and it's exactly what interviews probe.

A data structure is a way of organising data so you can use it efficiently — an array, a linked list, a tree. An algorithm is a step-by-step procedure to solve a problem — searching, sorting, finding a path. The art of DSA is matching the right structure and algorithm to each problem. Get it right and your program is instant; get it wrong and the same problem takes hours.


The crucial question: how fast does it scale?

Here's the insight beginners miss. We don't measure an algorithm's speed in seconds — that depends on the computer. We measure how the work grows as the input grows. If you double the data, does the work double? Quadruple? Stay the same? This is called time complexity, and we describe it with Big-O notation.

Consider finding a name in a list. If you check every entry one by one, doubling the list doubles your work. That's linear time, written O(n) — work grows in direct proportion to input size n. Now consider looking up a word in a dictionary by opening to the middle and halving your search each time. Doubling the dictionary adds just one extra step. That's logarithmic time, O(log n) — dramatically better at scale.


The complexity classes you must know

From fastest to slowest, these are the complexities that come up constantly in interviews:

  • O(1) — constant. Same work regardless of input size. Accessing arr[5] is O(1).
  • O(log n) — logarithmic. Halving the problem each step. Binary search.
  • O(n) — linear. Work proportional to input. Scanning a list once.
  • O(n log n) — log-linear. The best we can do for general sorting. Merge sort, quick sort.
  • O(n²) — quadratic. Nested loops over the data. Bubble sort. Gets slow fast.
  • O(2ⁿ) — exponential. Doubles with each added element. Usually a red flag to optimise.

Why does this matter so much? For a million items, an O(n) algorithm does a million steps; an O(n²) algorithm does a trillion. One finishes instantly, the other never finishes. Interviewers always ask "what's the time complexity?" — and knowing it is the difference between a passing and failing answer.


Reading complexity from code

You can often read the Big-O straight off the structure of the loops. A single loop over n items is O(n):

// O(n) -- one loop, n iterations
for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
}

A loop inside a loop, each running n times, is O(n²) — for each of n items you do n work:

// O(n^2) -- nested loops
for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
        cout << arr[i] * arr[j] << " ";
    }
}

And anything that halves the problem each step — like binary search — is O(log n). Training your eye to spot these patterns is a core interview skill we'll build throughout this course.


Space complexity too

Big-O also measures memory usage, called space complexity, with the same notation. An algorithm that creates a copy of the input uses O(n) extra space; one that works in place uses O(1). Interviewers often want both: "Can you do this in O(n) time and O(1) space?" Keeping an eye on both time and memory is what separates a working solution from an optimal one.

We'll use C++ throughout this course because it's the standard interview language — fast, explicit, and with a brilliant Standard Template Library. If you've done the C course, the syntax will feel familiar. In the next chapter we put theory to work with searching algorithms, where the difference between O(n) and O(log n) becomes vivid.

Reading mode · scroll to read at your own pace

Finished "What is DSA and Why Big-O Decides Everything"?

Mark this chapter complete so you can pick up exactly where you left off. Your progress saves locally — sign in to sync across devices.

Was this chapter clear?

Try it yourself — open the Code Playground15+ languages — Python, JavaScript, Java, C++, SQL & more — full IDE-style editor, instant run. Your code is auto-saved per language.