Back to Categories
CS Fundamentals

CS Fundamentals

Big O, data structures, algorithms, browser internals and HTTP

19Questions

🧠 Simple Definition (Word-for-word)

Big O describes how runtime scales with input size.


âš¡ Super Simple Line

Common complexities: O(1) constant — object property access, Map/Set get/has/add; O(n) linear — array forEach/map/filter, indexOf; O(log n) — binary search on sorted array; O(n log n) — Array.sort(); O(n^2) — nested loops.


âš¡ Key Details & Explanation

Big O describes how runtime scales with input size. Common complexities: O(1) constant — object property access, Map/Set get/has/add; O(n) linear — array forEach/map/filter, indexOf; O(log n) — binary search on sorted array; O(n log n) — Array.sort(); O(n^2) — nested loops. Space complexity similarly. In interviews: always state the complexity of your solution and why. Interviewer wants to hear 'this is O(n) time and O(1) space because...'. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

Big O describes how runtime scales with input size.

🧠 Simple Definition (Word-for-word)

Iterative: let prev = null, curr = head; while (curr) { let next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; — O(n) time, O(1) space.


âš¡ Super Simple Line

Recursive: function reverse(node, prev=null) { if (!node) return prev; let next = node.next; node.next = prev; return reverse(next, node); } — O(n) time, O(n) space (call stack).


âš¡ Key Details & Explanation

Iterative: let prev = null, curr = head; while (curr) { let next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; — O(n) time, O(1) space. Recursive: function reverse(node, prev=null) { if (!node) return prev; let next = node.next; node.next = prev; return reverse(next, node); } — O(n) time, O(n) space (call stack). Iterative is preferred for large lists (no stack overflow risk). This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

Iterative: let prev = null, curr = head; while (curr) { let next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; — O(n) time, O(1) space.

🧠 Simple Definition (Word-for-word)

Naive: nested loops O(n^2).


âš¡ Super Simple Line

Optimal O(n) with a hash set: const seen = new Set(); for (const num of nums) { const complement = target - num; if (seen.has(complement)) return [complement, num]; seen.add(num); } — One pass, O(n) time, O(n) space.


âš¡ Key Details & Explanation

Naive: nested loops O(n^2). Optimal O(n) with a hash set: const seen = new Set(); for (const num of nums) { const complement = target - num; if (seen.has(complement)) return [complement, num]; seen.add(num); } — One pass, O(n) time, O(n) space. For sorted array: two pointers O(n) time O(1) space — start at both ends, move inward based on sum vs target. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

Naive: nested loops O(n^2).

🧠 Simple Definition (Word-for-word)

BST: left subtree < node < right subtree.


âš¡ Super Simple Line

Insert: compare with current node, go left if smaller, right if larger, insert when null.


âš¡ Key Details & Explanation

BST: left subtree < node < right subtree. Insert: compare with current node, go left if smaller, right if larger, insert when null. Search: same traversal, return true when found. class Node { constructor(val) { this.val=val; this.left=this.right=null; } } insert: if (!root) return new Node(val); if (val < root.val) root.left = insert(root.left, val); else root.right = insert(root.right, val); return root. Worst case O(n) for unbalanced tree; O(log n) balanced. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

BST: left subtree < node < right subtree.

🧠 Simple Definition (Word-for-word)

BFS (breadth-first): explores level by level using a queue.


âš¡ Super Simple Line

Use for: shortest path in unweighted graph, finding closest nodes, level-order traversal.


âš¡ Key Details & Explanation

BFS (breadth-first): explores level by level using a queue. Use for: shortest path in unweighted graph, finding closest nodes, level-order traversal. DFS (depth-first): explores as deep as possible using a stack/recursion. Use for: detecting cycles, topological sort, exploring all paths, tree traversals (inorder, preorder, postorder). BFS implementation: const visited = new Set(); const queue = [start]; visited.add(start); while (queue.length) { const node = queue.shift(); for (const neighbor of graph[node]) { if (!visited.has(neighbor)) { visited.add(neighbor); queue.push(neighbor); } } } This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

BFS (breadth-first): explores level by level using a queue.

🧠 Simple Definition (Word-for-word)

DP: break problem into overlapping subproblems, solve each once and store results.


âš¡ Super Simple Line

Bottom-up coin change: given coins and amount, find minimum coins to make amount.


âš¡ Key Details & Explanation

DP: break problem into overlapping subproblems, solve each once and store results. Bottom-up coin change: given coins and amount, find minimum coins to make amount. function coinChange(coins, amount) { const dp = new Array(amount+1).fill(Infinity); dp[0] = 0; for (let i=1; i<=amount; i++) { for (const coin of coins) { if (coin <= i) dp[i] = Math.min(dp[i], dp[i-coin]+1); } } return dp[amount]===Infinity ? -1 : dp[amount]; } O(amount * coins.length) time. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

DP: break problem into overlapping subproblems, solve each once and store results.

🧠 Simple Definition (Word-for-word)

Recursive: function flatten(arr) { return arr.reduce((acc, val) => Array.isArray(val) ?


âš¡ Super Simple Line

acc.concat(flatten(val)) : [...acc, val], []); } Iterative (stack-based, avoids stack overflow for deeply nested): function flatten(arr) { const stack = [...arr]; const result = []; while (stack.length) { const item = stack.pop(); if (Array.isArray(item)) stack.push(...item); else result.push(item); } return result.reverse(); } This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another.


âš¡ Key Details & Explanation

Recursive: function flatten(arr) { return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatten(val)) : [...acc, val], []); } Iterative (stack-based, avoids stack overflow for deeply nested): function flatten(arr) { const stack = [...arr]; const result = []; while (stack.length) { const item = stack.pop(); if (Array.isArray(item)) stack.push(...item); else result.push(item); } return result.reverse(); } This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

Recursive: function flatten(arr) { return arr.reduce((acc, val) => Array.isArray(val) ?

🧠 Simple Definition (Word-for-word)

LRU evicts the least recently accessed item when capacity is reached.


âš¡ Super Simple Line

Optimal O(1) get and put: use a doubly linked list (order by recency) + HashMap (O(1) lookup).


âš¡ Key Details & Explanation

LRU evicts the least recently accessed item when capacity is reached. Optimal O(1) get and put: use a doubly linked list (order by recency) + HashMap (O(1) lookup). Get: if key in map, move node to front, return value. Put: if key exists, update and move to front. If at capacity, remove the tail (LRU). Add new node to front. In JS: use Map (insertion-ordered) as a shortcut — Map maintains insertion order, so delete+re-insert moves to end, and map.keys().next() gets the oldest. This gives O(1) operations. A practical answer should also mention how I would verify the choice, for example by checking query plans, measuring response time, or testing behavior under concurrent writes.


âš¡ One-line Interview Answer

LRU evicts the least recently accessed item when capacity is reached.

🧠 Simple Definition (Word-for-word)

Browser checks DNS cache, then OS cache, then DNS resolver → gets IP address.


âš¡ Super Simple Line

2.


âš¡ Key Details & Explanation

  1. Browser checks DNS cache, then OS cache, then DNS resolver → gets IP address. 2. TCP handshake with the server (3-way: SYN, SYN-ACK, ACK). 3. TLS handshake for HTTPS (negotiates cipher, exchanges certificates, establishes encrypted channel). 4. HTTP GET request sent. 5. Server processes request, sends HTTP response with HTML. 6. Browser parses HTML, constructs DOM. 7. Encounters CSS → fetch, parse, construct CSSOM. 8. Encounter JS → fetch, parse, execute (may block parsing). 9. DOM + CSSOM → Render tree → Layout → Paint → Composite → Display. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.

âš¡ One-line Interview Answer

Browser checks DNS cache, then OS cache, then DNS resolver → gets IP address.

🧠 Simple Definition (Word-for-word)

CRP: the sequence DOM → CSSOM → Render tree → Layout → Paint before first pixel appears.


âš¡ Super Simple Line

CSS is render-blocking (browser won't paint until CSSOM is ready).


âš¡ Key Details & Explanation

CRP: the sequence DOM → CSSOM → Render tree → Layout → Paint before first pixel appears. CSS is render-blocking (browser won't paint until CSSOM is ready). JS is parser-blocking by default (stops HTML parsing). Optimizations: async/defer scripts (defer maintains order, doesn't block parsing), inline critical CSS (above-the-fold styles), preload important resources, minimize CSS files, avoid large layout-causing JS on initial load, use font-display: swap for web fonts. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

CRP: the sequence DOM → CSSOM → Render tree → Layout → Paint before first pixel appears.

🧠 Simple Definition (Word-for-word)

HTTP/1.1: one request per TCP connection at a time (with keep-alive), text-based protocol, head-of-line blocking.


âš¡ Super Simple Line

HTTP/2: binary protocol, multiplexing (multiple requests over one connection simultaneously), header compression (HPACK), server push, stream prioritization.


âš¡ Key Details & Explanation

HTTP/1.1: one request per TCP connection at a time (with keep-alive), text-based protocol, head-of-line blocking. HTTP/2: binary protocol, multiplexing (multiple requests over one connection simultaneously), header compression (HPACK), server push, stream prioritization. HTTP/3: uses QUIC (UDP-based) instead of TCP — eliminates TCP head-of-line blocking, faster connection establishment (0-RTT reconnect), better performance on lossy networks (mobile). Vercel and Cloudflare support HTTP/3. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

HTTP/1.1: one request per TCP connection at a time (with keep-alive), text-based protocol, head-of-line blocking.

🧠 Simple Definition (Word-for-word)

A stack is LIFO: last in, first out.


âš¡ Super Simple Line

Operations are push and pop.


âš¡ Key Details & Explanation

A stack is LIFO: last in, first out. Operations are push and pop. Common uses: function call stack, undo history, DFS. A queue is FIFO: first in, first out. Operations are enqueue and dequeue. Common uses: task scheduling, BFS, message processing. Interviewers often care less about memorizing names and more about whether you can map the right structure to the right problem. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

A stack is LIFO: last in, first out.

🧠 Simple Definition (Word-for-word)

A collision happens when two keys map to the same bucket or index.


âš¡ Super Simple Line

Common strategies: separate chaining, where each bucket stores a list of entries, and open addressing, where the table probes for another empty slot.


âš¡ Key Details & Explanation

A collision happens when two keys map to the same bucket or index. Common strategies: separate chaining, where each bucket stores a list of entries, and open addressing, where the table probes for another empty slot. Good hash functions and resizing keep average operations near O(1), but worst case can degrade if collisions are excessive. In real systems, load factor and resize policy matter a lot. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

A collision happens when two keys map to the same bucket or index.

🧠 Simple Definition (Word-for-word)

Choose recursion when the problem is naturally recursive, such as tree traversal or divide-and-conquer, and the depth is safe.


âš¡ Super Simple Line

Choose iteration when you want tighter control over memory, avoid call-stack limits, or process large inputs reliably.


âš¡ Key Details & Explanation

Choose recursion when the problem is naturally recursive, such as tree traversal or divide-and-conquer, and the depth is safe. Choose iteration when you want tighter control over memory, avoid call-stack limits, or process large inputs reliably. Recursive code can be cleaner; iterative code is often safer in production JavaScript because deep recursion can overflow the stack. This matters because computer science fundamentals help explain why one solution is faster, safer, or more reliable than another. Even when the topic is browser or HTTP behavior, the goal is to explain the sequence clearly and connect it to debugging or performance.


âš¡ One-line Interview Answer

Choose recursion when the problem is naturally recursive, such as tree traversal or divide-and-conquer, and the depth is safe.

🧠 Simple Definition (Word-for-word)

An Operating System Kernel is the core computer program at the heart of an OS, possessing complete control over everything in the system. It acts as a bridge between application software and physical computer hardware, managing system resources. Its key responsibilities are: Memory management, Process scheduling, Device driver communication, and System calls.


âš¡ Super Simple Line

Kernel = the core translator and controller that connects software apps to physical CPU, RAM, and hardware.


📋 Core Responsibilities

  • Process Management: Allocates CPU execution time to different running programs (processes) using schedulers.

  • Memory Management: Keeps track of physical RAM allocations, virtual memory address mapping, and prevents processes from overwriting each other's memory.

  • Device Management: Acts as an intermediary between hardware peripherals (disks, keyboards, GPUs) and applications using device drivers.

  • System Calls: Exposes secure APIs (like file reading or socket creation) to user applications since they cannot access hardware directly.


âš¡ One-line Interview Answer

The kernel is the foundational core of an operating system that manages hardware resources, processes scheduling, and memory allocation while exposing secure system call APIs to applications.

🧠 Simple Definition (Word-for-word)

SOLID is a set of design principles that help write clean and maintainable code.


âš¡ Super Simple Line

Single Responsibility → one class should have one responsibility Open/Closed → open for extension, closed for modification Liskov Substitution → child classes should behave like parent Interface Segregation → don’t force classes to implement unused methods Dependency Inversion → depend on abstractions, not concrete implementations


âš¡ Key Details & Explanation

SOLID is a set of design principles that help write clean and maintainable code.

  • Single Responsibility → one class should have one responsibility
  • Open/Closed → open for extension, closed for modification
  • Liskov Substitution → child classes should behave like parent
  • Interface Segregation → don’t force classes to implement unused methods
  • Dependency Inversion → depend on abstractions, not concrete implementations

âš¡ One-line Interview Answer

SOLID is a set of design principles that help write clean and maintainable code.

🧠 Simple Definition (Word-for-word)

Method Overloading is when you have multiple methods with the same name but different parameters (not supported in JavaScript).


âš¡ Super Simple Line

Method Overriding is when a subclass provides a specific implementation of a method that is already defined in its superclass.


âš¡ Key Details & Explanation

  • Method Overloading is when you have multiple methods with the same name but different parameters (not supported in JavaScript).
  • Method Overriding is when a subclass provides a specific implementation of a method that is already defined in its superclass.

âš¡ One-line Interview Answer

Method Overloading is when you have multiple methods with the same name but different parameters (not supported in JavaScript).

🧠 Simple Definition (Word-for-word)

Abstraction means hiding complex implementation details and exposing only what’s necessary.


âš¡ Super Simple Line

Abstraction means hiding complex implementation details and exposing only what’s necessary.


âš¡ Key Details & Explanation

Abstraction means hiding complex implementation details and exposing only what’s necessary.


âš¡ One-line Interview Answer

Abstraction means hiding complex implementation details and exposing only what’s necessary.

🧠 Simple Definition (Word-for-word)

Object-Oriented Programming (OOP) is a programming paradigm that organizes code around objects, which are instances of classes.


âš¡ Super Simple Line

The core principles of OOP are: Encapsulation: Bundling data and methods that operate on that data within a single unit (class).


âš¡ Key Details & Explanation

Object-Oriented Programming (OOP) is a programming paradigm that organizes code around objects, which are instances of classes. The core principles of OOP are:

  • Encapsulation: Bundling data and methods that operate on that data within a single unit (class).
  • Inheritance: Creating new classes based on existing ones to promote code reusability.
  • Polymorphism: Allowing objects of different classes to be treated as objects of a common superclass, typically through method overriding.
  • Abstraction: Hiding complex implementation details and exposing only the necessary features to the user.

These principles help in creating modular, reusable, and maintainable code.


âš¡ One-line Interview Answer

Object-Oriented Programming (OOP) is a programming paradigm that organizes code around objects, which are instances of classes.