The theory that written tests and campus interviews love: processes and threads, memory, deadlocks, OSI/TCP, DNS, ACID, normalisation and design patterns.
Readiness: 0 of 33 nailed
How to use this page:1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready
A process is a running program with its own private memory, like a separate house. Threads are workers inside one house: they share the same rooms (memory), so they’re cheaper to create and can talk easily, but they can also trip over each other.
Say it like this in the interview
“A process is an independent program in execution with its own address space and resources. Threads are units of execution within a process that share its memory and resources but have their own stack and registers. Threads are lighter and communicate faster through shared memory, but need synchronisation to avoid race conditions. A crashing thread can bring down the whole process; separate processes are isolated.”
They will probably ask next
“What is a context switch?” Saving one task’s state and loading another’s; switching between threads is cheaper than between processes.
Two people each hold one key and wait for the other’s key forever. Neither lets go, so nobody moves.
Say it like this in the interview
“A deadlock is when processes wait on each other’s resources forever. The four Coffman conditions must all hold: mutual exclusion, hold and wait, no preemption, and circular wait. Breaking any one prevents it. The most practical way is to always acquire locks in a fixed global order, or use timeouts.”
They will probably ask next
“Deadlock vs starvation?” Starvation: a process waits indefinitely because others keep getting priority, even though no cycle exists.
The stack is a neat pile of plates: each function call adds a plate with its local variables and removes it when done. Fast and automatic, but small. The heap is a big storeroom for objects that must live longer or are large; it’s slower, and something must clean it (you, or a garbage collector).
Say it like this in the interview
“The stack stores function frames and local variables in LIFO order, is fast, per-thread and limited in size; overflowing it with deep recursion causes a stack overflow. The heap stores dynamically allocated objects, is shared, larger and slower, and is managed manually or by a garbage collector; forgetting to free memory causes leaks.”
Each program is told it has a huge private memory. Behind the scenes the OS maps those pretend addresses onto real RAM in fixed-size chunks (pages), and moves pages to disk when RAM is full.
Say it like this in the interview
“Virtual memory gives each process its own address space mapped to physical memory by the MMU through page tables. Memory is divided into pages; when a page isn’t in RAM, a page fault loads it from disk. It provides isolation and lets programs use more memory than physically available, at the cost of thrashing if swapping is excessive.”
How the OS decides who uses the CPU next, like a queue at a counter: first come first served, shortest job first, or everyone gets a short turn in rotation.
Say it like this in the interview
“FCFS is simple but suffers the convoy effect; SJF minimises average waiting time but needs burst estimates and can starve long jobs; Round Robin gives each process a time quantum, good for responsiveness; priority scheduling can starve low priorities, fixed with aging. Real systems use multilevel feedback queues.”
A mutex is the single key to a bathroom: one person at a time, and only the one who locked it unlocks it. A semaphore is a counter of available parking spots: up to N cars at once.
Say it like this in the interview
“A mutex provides mutual exclusion with ownership: only the locking thread unlocks. A counting semaphore allows up to N concurrent holders and is used for limiting access to a pool of resources or signalling between threads. A binary semaphore is similar to a mutex but without ownership.”
When two things happen at the same time and the result depends on which finishes first. Two people withdrawing from the same account at once might both see enough money.
Say it like this in the interview
“A race condition is when correctness depends on timing between concurrent operations, like read-modify-write on a shared counter or balance. Prevent it with locks, atomic operations, transactions or designing for idempotency.”
Fast memory is small and expensive; big memory is slow. Computers keep recently used data in the fastest layers (CPU cache, then RAM, then disk).
Say it like this in the interview
“Registers, L1/L2/L3 caches, RAM and disk trade speed for size. Programs that access memory sequentially benefit from cache locality, which is why arrays are often faster than linked lists in practice.”
Concurrency: juggling many tasks by switching between them (one cook, several dishes). Parallelism: actually doing several at the same instant (several cooks).
Say it like this in the interview
“Concurrency is structuring a program to handle multiple tasks that overlap in time; parallelism is executing them simultaneously on multiple cores. Node is concurrent but single-threaded for JS; worker threads add parallelism.”
Sending a parcel: you write the letter (application), choose a courier service that guarantees delivery (transport, TCP), the address system routes it across cities (network, IP), and trucks carry it on roads (link and physical).
7 Application HTTP, DNS, SMTP
6 Presentation encryption/encoding (TLS often placed here)
5 Session sessions
4 Transport TCP, UDP (ports)
3 Network IP (IP addresses, routers)
2 Data link Ethernet, Wi-Fi (MAC addresses, switches)
1 Physical cables, radio
Say it like this in the interview
“Seven layers: physical, data link, network, transport, session, presentation, application. HTTP is application layer, TCP and UDP transport, IP network. In practice we use the simpler four-layer TCP/IP model: link, internet, transport, application.”
Traps that make people fail
Mixing up switches (layer 2, MAC) and routers (layer 3, IP).
TCP is a phone call: connect first, everything arrives in order, lost pieces are resent. UDP is shouting messages: no connection, faster, but some may get lost or arrive out of order. Video calls and games prefer UDP because late data is useless anyway.
Say it like this in the interview
“TCP is connection-oriented with a three-way handshake, reliable ordered delivery, flow and congestion control. UDP is connectionless, lightweight, without delivery guarantees. TCP for web, email and file transfer; UDP for DNS, streaming, VoIP and games. HTTP/3 runs on QUIC, which is built on UDP.”
“Can you hear me?” (SYN) → “Yes, can you hear me?” (SYN-ACK) → “Yes!” (ACK). Now both sides know the line works both ways.
Say it like this in the interview
“The client sends SYN with its initial sequence number, the server replies SYN-ACK with its own and acknowledges the client’s, and the client sends ACK. Then data flows. Closing uses a four-step FIN/ACK exchange.”
DNS is the internet’s phone book: you know the name (example.com), DNS finds the number (IP address). It asks step by step: root servers → .com servers → the domain’s own servers, and caches answers along the way.
Say it like this in the interview
“The resolver checks caches (browser, OS, ISP), then queries root servers, which point to the TLD servers, which point to the domain’s authoritative nameservers that return the record, such as A, AAAA, CNAME or MX. Results are cached according to TTL, which is why DNS changes take time to propagate.”
HTTPS = HTTP inside an encrypted tunnel. The server proves its identity with a certificate signed by a trusted authority, then both sides agree on a secret key nobody listening can figure out.
Say it like this in the interview
“HTTPS is HTTP over TLS. During the handshake the server presents a certificate that the client verifies against trusted CAs; they use asymmetric cryptography, like ECDHE key exchange, to agree on a shared session key; then data is encrypted with fast symmetric encryption. It gives confidentiality, integrity and authentication. Default ports: 80 for HTTP, 443 for HTTPS.”
An IP address is a building’s street address; a port is the apartment number (which program in that building). IPv4 ran out of addresses, so IPv6 has vastly more.
Say it like this in the interview
“IP identifies a host; a port identifies a process or service on it, like 443 for HTTPS. IPv4 is 32-bit (about 4.3 billion addresses, extended with NAT); IPv6 is 128-bit. Private ranges like 192.168.x.x aren’t routable on the internet.”
It’s a receptionist sending each visitor to whichever server is free, and skipping servers that are down.
Say it like this in the interview
“Distributes traffic across servers using algorithms like round-robin or least connections, performs health checks, terminates TLS, and enables horizontal scaling and zero-downtime deploys. Layer 4 balances by connection; layer 7 by HTTP content.”
A network of servers around the world that keep copies of your images, CSS and pages, so users download from a nearby server instead of your faraway one.
Say it like this in the interview
“A CDN caches content at edge locations close to users, reducing latency and origin load, and often adds DDoS protection and TLS. Cache headers control what’s cached and for how long.”
The four promises a database makes about a transaction like a bank transfer: all-or-nothing, rules stay valid, transactions don’t interfere, and saved data survives crashes.
Say it like this in the interview
“Atomicity: all operations succeed or none do. Consistency: constraints hold before and after. Isolation: concurrent transactions behave as if run one by one, to the chosen isolation level. Durability: committed data survives crashes, via the write-ahead log.”
1NF: one value per cell. No “phone1, phone2” columns or comma lists.
2NF: every column depends on the whole key, not part of it.
3NF: columns depend only on the key, not on other non-key columns (store the city’s province in a cities table, not in every customer row).
Bad: orders(order_id, product_id, product_name, customer_name, customer_city)
1NF: atomic values only
2NF: product_name depends only on product_id -> move to products(product_id, name)
3NF: customer_city depends on customer, not on the order -> customers(id, name, city)
Say it like this in the interview
“1NF requires atomic values and no repeating groups. 2NF removes partial dependency on part of a composite key. 3NF removes transitive dependency, where a non-key column depends on another non-key column. The goal is each fact stored once to avoid update anomalies.”
Primary key: the official ID of each row. Unique and never null.
Candidate keys: all columns that *could* be the ID (email, CNIC).
Unique key: must be unique, but can be optional.
Foreign key: a column pointing to another table’s primary key (orders.customer_id).
Say it like this in the interview
“A primary key uniquely identifies rows, chosen from candidate keys, and can’t be null. A unique constraint enforces uniqueness on other columns. A foreign key enforces referential integrity between tables, with options like cascade delete.”
A clustered index is how the book’s pages are physically ordered (only one possible order). A non-clustered index is the index at the back pointing to page numbers; you can have many.
Say it like this in the interview
“A clustered index defines the physical order of rows; there’s one per table, usually the primary key in InnoDB and SQL Server. Non-clustered indexes are separate structures with pointers or the primary key back to the row. A covering index includes all columns a query needs, avoiding the lookup.”
Key-value (Redis), document (MongoDB), wide-column (Cassandra), graph (Neo4j). Each is optimised for a different way of reading data.
Say it like this in the interview
“Key-value for caching and sessions, document for flexible nested records, wide-column for massive write-heavy time series, graph for relationship-heavy queries like recommendations. Relational is still the default for transactional data.”
Singleton: only one instance ever exists (a database connection manager, app config).
Factory: a function decides which class to create for you: PaymentFactory.create('stripe').
Observer: subscribers get notified when something happens: YouTube subscribers, event listeners, WordPress hooks.
class Config {
private static ?Config $instance = null;
private function __construct() {}
public static function get(): Config {
return self::$instance ??= new Config();
}
}
Say it like this in the interview
“Singleton restricts a class to one instance with global access; useful but it hides dependencies and complicates testing, so I prefer injecting a single instance. Factory encapsulates object creation so callers depend on an interface. Observer defines a one-to-many dependency where subjects notify subscribers; event emitters and WordPress hooks are examples.”
They will probably ask next
“Name other patterns you’ve used.” Strategy (swap algorithms), Adapter (wrap a third-party API), Repository (data access), Decorator (middleware).
SDLC is the life of software: plan → design → build → test → deploy → maintain. Waterfall does each step once, in order, like building a bridge. Agile loops through all steps in short sprints, showing working software every 1–2 weeks and adjusting.
Say it like this in the interview
“The SDLC covers requirements, design, implementation, testing, deployment and maintenance. Waterfall is sequential and suits fixed, well-understood requirements; Agile is iterative, with Scrum sprints, standups, reviews and retrospectives, and suits changing requirements with frequent feedback.”
A compiled language is translated to machine code before running (C++, Go). An interpreted one is read and executed line by line at runtime (classic PHP, Python). Java is in between: compiled to bytecode, then run by the JVM.
JVM runs bytecode.
JRE = JVM + libraries, to run Java.
JDK = JRE + compiler and tools, to develop Java.
Say it like this in the interview
“Compiled languages translate ahead of time into machine code; interpreted ones execute through an interpreter at runtime; many modern runtimes use JIT compilation. For Java: the JVM executes bytecode, the JRE bundles the JVM with the standard libraries, and the JDK adds the compiler and dev tools.”
Overloading: same method name, different parameters, in one class. Overriding: a child class replaces a parent’s method with its own version.
Say it like this in the interview
“Overloading is compile-time polymorphism with different signatures (Java, C#; PHP and JS don’t support it natively). Overriding is runtime polymorphism where a subclass provides its own implementation of an inherited method.”
Encapsulation hides the data inside an object and only allows access through methods. Abstraction hides complexity: you use a simple interface without knowing the inner details.
Say it like this in the interview
“Encapsulation is about bundling data with methods and restricting direct access via private fields. Abstraction is about exposing what something does through interfaces or abstract classes, hiding how. They work together.”
Inheritance locks classes into a family tree that’s hard to change. Composition builds objects from smaller parts you can swap.
Say it like this in the interview
“Deep inheritance couples subclasses to parent internals and breaks easily. Composition, holding references to collaborators via interfaces, is more flexible and testable. I use inheritance for true is-a relationships with stable base classes.”
How much extra memory an algorithm needs as input grows. Copying an array needs O(n) extra; swapping in place needs O(1).
Say it like this in the interview
“Extra memory relative to input size: two-pointer algorithms use O(1), hash-map solutions O(n), recursion uses O(depth) stack. There’s often a time versus space trade-off.”
A hash function turns a key into a number that says which bucket to put it in, so lookup jumps straight there. A collision is when two keys land in the same bucket.
Say it like this in the interview
“Keys are hashed to bucket indexes, giving average O(1) operations. Collisions are handled by chaining (lists per bucket) or open addressing (probing). The table resizes when the load factor grows; a bad hash function degrades to O(n).”
An array is a row of numbered boxes next to each other: instant access by number. A linked list is a chain where each box points to the next: easy to insert in the middle, slow to find item #500.
Say it like this in the interview
“Arrays give O(1) index access and cache locality, O(n) middle inserts. Linked lists give O(1) insert or delete with a node reference, O(n) access. In practice dynamic arrays win most of the time.”
A structure where the smallest (or largest) item is always on top and quick to remove. Like a hospital queue where the most urgent patient goes first.
Say it like this in the interview
“A binary heap gives O(1) peek and O(log n) insert and remove of the min or max. Used for priority queues, scheduling, Dijkstra’s algorithm, top-k problems and merging sorted lists.”
A tree is a family tree: one root, no loops, each child has one parent. A graph is a general network (roads, friendships) that can have loops and many connections.
Say it like this in the interview
“A tree is a connected acyclic graph with n−1 edges and a hierarchy; graphs can be directed or undirected, cyclic, weighted. Represented by adjacency lists or matrices.”