Back to Tech Interviews

Core CS Fundamentals Interview Questions

Master Operating Systems, Computer Networks, Object-Oriented Design (OOP), and System Architecture patterns

Total: 18 QuestionsLearned: 0 / 18 (0%)
Difficulty Filters

Tools & Options
Showing 18 of 18 questions
Beginner
What is the difference between a Process and a Thread? Explain Context Switching.

Process vs Thread:

1. Process:

- An executing instance of a program with its own dedicated memory space (Code, Data, Heap, Stack).

- Processes are isolated from each other. Communication requires Inter-Process Communication (IPC).

- Heavyweight: Process creation and context switching have high OS resource overhead.

- Crash Isolation: If one process crashes, it does not affect other processes.

2. Thread:

- A thread is the smallest unit of CPU execution within a process (often called a lightweight process).

- Threads belonging to the same process share the same memory space (Heap, Code, Data), but maintain their own private Stack, Registers, and Program Counter (PC).

- Lightweight: Thread creation and context switching are significantly faster.

- Crash Impact: If an unhandled exception crashes one thread, it can crash the entire host process.

Context Switching:

Context switching is the process where the CPU saves the execution state (registers, program counter, stack pointer) of a currently running process/thread and loads the saved state of another process/thread to resume execution. Thread context switching is faster because page tables and memory mappings do not need to be swapped.

// Conceptual Multi-threading vs Multi-processing in JS (Worker Threads vs Child Processes)
const { Worker, isMainThread, parentPort } = require('worker_threads');

if (isMainThread) {
  // Main thread spawns a worker thread (Shares memory options via SharedArrayBuffer)
  const worker = new Worker(__filename);
  worker.on('message', (msg) => console.log('Received from worker:', msg));
} else {
  // Worker thread executing in background
  parentPort.postMessage('Task finished on thread ID: ' + require('worker_threads').threadId);
}
Beginner
Explain CPU Scheduling Algorithms: FCFS, SJF, Round Robin, and Priority Scheduling.

CPU Scheduling determines which process in the ready queue receives CPU execution time.

Common Scheduling Algorithms:

1. First-Come, First-Served (FCFS):

- Non-preemptive. Processes are executed in arrival order.

- Drawback: Convoy Effect (short processes wait behind a long process, increasing average waiting time).

2. Shortest Job First (SJF) / Shortest Remaining Time First (SRTF):

- Selects process with shortest CPU burst time. SRTF is preemptive.

- Optimal for minimizing average waiting time.

- Drawback: Starvation of long processes.

3. Round Robin (RR):

- Preemptive. Each process gets a fixed time quantum (e.g. 10ms) in round-robin sequence.

- Ideal for time-sharing systems. Performance depends heavily on time quantum size (too large = FCFS, too small = excessive context switching overhead).

4. Priority Scheduling:

- CPU allocated to highest priority process. Can be preemptive or non-preemptive.

- Drawback: Starvation of low priority processes. Solution: Aging (gradually increasing process priority over time).

// Round Robin CPU Scheduling Simulation Concept
function roundRobin(processes, quantum) {
  let queue = [...processes];
  let time = 0;
  
  while (queue.length > 0) {
    let p = queue.shift();
    if (p.remainingTime > quantum) {
      time += quantum;
      p.remainingTime -= quantum;
      queue.push(p); // Re-queue process
    } else {
      time += p.remainingTime;
      p.remainingTime = 0;
      p.completionTime = time;
      console.log(`Process ${p.id} completed at time ${time}`);
    }
  }
}
Intermediate
What is Process Synchronization? Explain Mutex vs Semaphore and the Producer-Consumer Problem.

Process Synchronization prevents race conditions when concurrent processes/threads access shared data (Critical Section).

Race Condition: Occurs when multiple threads read/write shared data concurrently, and the final output depends on execution timing.

Mutex (Mutual Exclusion Lock):

- A locking mechanism used to synchronize access to a resource.

- Binary nature (Locked / Unlocked).

- Ownership Rule: The thread that locks the Mutex MUST be the thread that unlocks it.

Semaphore:

- A signaling mechanism using an integer counter variable.

- Counting Semaphore: Allows up to N threads to access a resource concurrently.

- Binary Semaphore: Value ranges between 0 and 1 (similar to Mutex, but has no thread ownership restrictions).

Producer-Consumer Problem:

Producers generate items into a fixed-size buffer; Consumers remove items. Uses 3 semaphores:

1. Mutex: Ensures exclusive access to buffer.

2. Empty Semaphore (Count = Buffer Size): Tracks empty slots.

3. Full Semaphore (Count = 0): Tracks filled slots.

// Mutex Pattern Implementation in JS
class Mutex {
  constructor() {
    this._lock = Promise.resolve();
  }

  async acquire() {
    let release;
    const nextLock = new Promise(resolve => {
      release = resolve;
    });
    const currentLock = this._lock;
    this._lock = this._lock.then(() => nextLock);
    await currentLock;
    return release; // Callback to unlock mutex
  }
}

// Usage in Critical Section
const mutex = new Mutex();
async function safeCriticalSection() {
  const unlock = await mutex.acquire();
  try {
    // Critical Section: Access shared resource safely
  } finally {
    unlock(); // Release lock
  }
}
Intermediate
What is a Deadlock? Explain the 4 Necessary Conditions for Deadlock and how to Prevent it.
Intermediate
Explain Virtual Memory, Paging, Page Faults, Thrashing, and LRU Page Replacement.
Intermediate
Explain Inter-Process Communication (IPC): Shared Memory vs Message Passing vs Sockets.
Beginner
Explain the OSI 7-Layer Model vs TCP/IP 4-Layer Model and layer-by-layer functions.
Intermediate
Explain TCP vs UDP protocols, TCP 3-Way Handshake, and 4-Way Teardown.
Intermediate
What is the difference between HTTP, HTTPS, HTTP/1.1, HTTP/2, and HTTP/3?
Intermediate
Explain the DNS Resolution Process step-by-step.
Intermediate
Compare Real-Time Web Communication: WebSockets vs HTTP Long Polling vs Server-Sent Events (SSE).
Intermediate
Explain IP Addressing: IPv4 vs IPv6, Subnetting, CIDR Notation, and NAT.
Beginner
What are the 4 Pillars of Object-Oriented Programming (OOP)? Provide practical code examples.
Advanced
Explain the SOLID Principles of Object-Oriented Design with examples.
Intermediate
Explain the Singleton Pattern and how to implement a Thread-Safe Singleton.
Intermediate
Explain Creational Patterns: Factory Method Pattern and Builder Pattern.
Intermediate
Explain Behavioral & Structural Patterns: Observer Pattern and Strategy Pattern.
Advanced
Why is 'Composition over Inheritance' a fundamental software engineering principle?

Technical Interview Mastery Blueprint

Proven methodologies and frameworks to succeed in technical and architecture rounds.

1. The Engineering STAR Technique

When responding to architectural or situational questions, structure your answer using Situation, Technical Constraint, Action, and Measurable Result. Rather than jumping straight to syntax, articulate the business problem, why certain patterns (e.g. caching, queuing, immutability) were selected over alternatives, and what latency or throughput improvements were achieved.

2. Defending Architectural Trade-Offs

Senior interviewers evaluate how you weigh trade-offs. Always explain why you chose an approach: e.g., memory overhead vs CPU cycle speed, consistency vs availability (CAP theorem), or normalized schemas vs denormalized fast reads. Stating the drawbacks of your own proposal demonstrates maturity and production experience.

3. Clean Code & Edge-Case Proactivity

In live-coding rounds, communicate your thinking aloud before typing. State edge cases explicitly: null or undefined inputs, extreme boundary values, concurrency races, and network timeouts. Writing modular, well-named functions with deterministic unit tests separates junior candidates from staff-level engineers.

4. Antipatterns to Avoid

Avoid reciting memorized definitions without practical context. Never dismiss non-functional requirements such as security (CSRF, injection, token rotation), observability (logging, metrics), and accessibility (ARIA, semantic standards). Always ask clarifying scope questions before writing complex implementations.

Continuous learning: Practice daily, mark completed questions as learned, and revisit difficult concepts.Explore All Interview Tracks →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools