← Back to Blog

Computer Science Fundamentals for Data Science Interviews

Yes, Data Scientists Get CS Questions

You're not interviewing for a SWE role, but Google, Meta, and Stripe still probe CS fundamentals in data science loops — usually to check you can reason about the cost of your own code. A pandas pipeline that accidentally does an O(n²) scan on 100M rows is a real production incident, and interviewers know it.

The good news: the question pool is small and predictable.

Big O: The Filter Question

"What's the complexity of your solution?" follows almost every coding exercise. Big O describes how runtime or memory grows with input size, keeping only the dominant term — an algorithm doing 3n² + 100n operations is O(n²).

Structure / operation Average case
Hash table lookup O(1)
Array index O(1)
Binary search (sorted data) O(log n)
Single scan O(n)
Sorting O(n log n)
Nested loop over pairs O(n²)

Memorize this table — it answers half the complexity follow-ups you'll ever get. Practice: Big O Notation Basics.

Hash Tables: The Data Scientist's Best Friend

Every "have I seen this before?" and "count things by key" pattern — Python dicts, pandas groupby internals, feature hashing — is a hash table. Know the mechanism (hash the key, jump to a bucket, handle collisions) and the payoff (O(1) average lookup/insert). Practice: Hash Table Operations.

Binary Search and Its One Requirement

def binary_search(arr, target):
    lo, hi = 0, len(arr) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        if arr[mid] == target:
            return mid
        if arr[mid] < target:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1

The trap in the question is the precondition: the data must be sorted. Interviewers love asking why, and what happens if it isn't. Practice: Binary Search Requirements.

Stacks, Queues, Arrays, Linked Lists

Two quick-fire comparisons appear constantly:

  • Stack vs queue — LIFO vs FIFO. Stacks power undo, recursion, and DFS; queues power task processing and BFS. Practice: Stack vs Queue
  • Linked list vs array — arrays give O(1) indexing but O(n) middle-insertion; linked lists flip that. In data work you almost always want arrays (hello, NumPy), and saying why — memory locality — is a strong-signal answer. Practice: Linked List vs Array

BFS vs DFS

Graph traversal shows up in data science interviews via real scenarios: finding connected components of users, shortest paths in a network, crawling dependencies. BFS explores level by level with a queue and finds shortest paths in unweighted graphs; DFS dives deep with a stack (or recursion) and uses less memory on wide graphs. Practice: BFS vs DFS.

How Deep to Go

You will almost never be asked to implement a red-black tree. Target this bar instead:

  1. State the complexity of anything you write, unprompted.
  2. Know when a dict beats a list, and why sorted data unlocks binary search.
  3. Recognize BFS/DFS/hash-table patterns inside "product-flavored" questions.

All 20 CS questions on the site are pitched at exactly this data-science-interview level.

Practice Makes Perfect

Ready to test your skills?

Practice real Computer Science interview questions from top companies — with solutions.

Get interview tips in your inbox

Join data scientists preparing smarter. No spam, unsubscribe anytime.