Study Material Interview
Study Material Interview
This guide is structured to help you build a deep, interconnected mental model of the core fundamentals
of computer science. It is not designed for rote memorization. Instead, it aims to provide a strategic
pathway for preparation, moving from foundational concepts to practical application and advanced
design discussions. The content is organized by topic and sub-topic, with questions tiered from basic to
intermediate and advanced, mirroring the natural progression of a technical interview. 1 By
understanding the "why" behind each concept and question, you can develop the robust and flexible
knowledge base required to excel.
The core of any OOP discussion revolves around four main principles: Encapsulation, Abstraction,
Inheritance, and Polymorphism. Answering questions about these pillars requires more than just reciting
definitions; it demands an understanding of their purpose and the mechanisms by which they are
implemented.6
Encapsulation
Concept: Encapsulation is the practice of bundling data (attributes) and the methods (functions) that
operate on that data into a single, self-contained unit known as a class.9 The primary goal of
encapsulation is to protect an object's internal state from outside interference and misuse. This principle
is often described as "data hiding".10 By restricting direct access to an object's data, the class can
maintain its own state integrity, ensuring that data is only modified through a well-defined public
interface.
A private member can only be accessed by other methods within the same class. This is the strictest
level of encapsulation.
A public member can be accessed from anywhere, by any code that has a reference to the object. This
forms the object's public interface.
A protected member is accessible within its own class and by any subclasses that inherit from it. 7
A classic real-world example is a BankAccount class. The balance attribute should be declared
private to prevent arbitrary changes. To modify the balance, the class provides public methods like
deposit(amount) and withdraw(amount). This ensures that all changes to the balance are validated
(e.g., checking for sufficient funds during a withdrawal) and controlled by the class itself.11
Abstraction
Concept: Abstraction is the process of hiding complex implementation details from the user and
exposing only the necessary and relevant features.9 It simplifies complex systems by modeling classes
appropriate to the problem and providing a clear, high-level interface for interacting with those classes.
The goal is to manage complexity.
Interview Focus: A frequent and crucial follow-up question is to differentiate abstraction from
encapsulation. While related, they are distinct concepts. Encapsulation is a mechanism for hiding data
and bundling it with its operating methods. Abstraction is a design principle for hiding complexity and
exposing only essential functionality. In essence, encapsulation is the implementation, while abstraction
is the design-level concept it helps achieve.5
A powerful analogy is driving a car. The driver interacts with a simple interface: a steering wheel,
accelerator, and brake pedal. This is abstraction. The driver doesn't need to know the intricate details of
the internal combustion engine, the transmission system, or the braking hydraulics. Those complex
systems are hidden. Encapsulation, in this analogy, would be the engine block itself, which bundles all
the engine's components (pistons, cylinders) together and protects them from direct external
manipulation.12 In programming, abstraction is often implemented using abstract classes and interfaces. 9
Inheritance
Concept: Inheritance is a fundamental mechanism that allows a new class (known as a subclass, child
class, or derived class) to be based on an existing class (a superclass, parent class, or base class). The
subclass acquires, or inherits, the attributes and methods of the superclass, enabling code reuse and the
creation of a logical hierarchy.4 This represents an "is-a" relationship; for example, a
Car is a Vehicle.
Interview Focus: Questions on inheritance often explore its different forms and language-specific rules.
The common types of inheritance are 4:
Polymorphism
Concept: Polymorphism, from the Greek for "many forms," is the ability of an object, variable, or
method to take on multiple forms. In OOP, it allows a single interface (like a method name) to represent
different underlying forms (implementations).4 This provides flexibility and enables code to be written
more generically.
Interview Focus: This is one of the most important OOP topics in an interview. A candidate must
clearly distinguish between the two types of polymorphism 4:
1. Compile-Time Polymorphism (Static Polymorphism): This form is resolved at compile time. The
compiler determines which method to call based on the method signature (the method name and the
number, type, and order of its parameters). It is achieved through:
o Method Overloading: Defining multiple methods in the same class with the same name but different
parameters. For example, a calculateArea method could be overloaded to accept a radius (for a
circle) or a length and width (for a rectangle).10
o Operator Overloading: Redefining the behavior of an operator (like + or *) for a custom class type.
This is supported in C++ but not in Java.14
2. Runtime Polymorphism (Dynamic Polymorphism): This form is resolved at runtime. It is achieved
through method overriding, where a subclass provides a specific implementation for a method that is
already defined in its superclass. In languages like C++ and C#, this requires the base class method to be
marked with the virtual keyword, and the derived class method with the override keyword. In Java,
methods are virtual by default. This allows a base class reference variable to call the overridden method
in the derived class object it is pointing to, which is a powerful feature for creating extensible systems. 4
A recurring pattern in technical interviews is the "compare and contrast" question. This is not a test of
simple memorization but a deliberate probe into a candidate's design thinking. Real-world software
development is a series of choices, each with benefits and drawbacks. By asking a candidate to compare
two related concepts, an interviewer assesses their ability to analyze these trade-offs and justify design
decisions. A strong candidate can articulate not just the technical differences but also the specific
scenarios where one choice would be more appropriate than the other.
Overloading vs. Overriding: This is the most direct test of understanding the two types of
polymorphism. Overloading is about having multiple methods with the same name but different
signatures in the same class to offer convenience (compile-time polymorphism). Overriding is about a
subclass providing a specific implementation for a method defined in its superclass to alter behavior
(runtime polymorphism).5
Composition vs. Inheritance: This probes deeper into design philosophy. Inheritance creates a strong,
tightly-coupled "is-a" relationship. Composition creates a more flexible, loosely-coupled "has-a"
relationship by including an instance of another class as a member variable. For example, a Car is a
Vehicle (inheritance), but a Car has an Engine (composition). Experienced developers often favor
composition over inheritance because it offers greater flexibility and avoids the rigidity of deep
inheritance hierarchies.4
Class vs. Struct (in C++): This is a language-specific but important distinction. The primary technical
difference is that members of a struct are public by default, while members of a class are private
by default. Culturally, structs are typically used for simple Plain Old Data (POD) structures without
complex behavior, while classes are used for objects with methods, constructors, and richer behavior.9
Abstract Class vs. Interface: This is arguably the most common and important design-level
comparison. Both are used to achieve abstraction, but they do so with different capabilities and
intentions. A candidate must be able to articulate these differences clearly.
Feature Abstract Class Interface
Can have instance variables (member fields) Can only have variables that are implicitly
Variables of any type (final, non-final, static, non- public, static, and final
static).16 (constants).16
Feature Abstract Class Interface
To provide a common base class with some To define a pure "contract" of behaviors that
shared code and some abstract behavior for a class must implement, without dictating
Purpose
a group of closely related classes (an "is-a" anything about its inheritance hierarchy (a
relationship). "can-do" relationship).16
A strong answer would conclude that you choose an abstract class when you want to provide a common
base implementation for a family of related objects. You choose an interface when you want to define a
role or capability that disparate classes can implement, regardless of where they are in the class
hierarchy.
Beyond the four pillars, interviewers will test a candidate's working knowledge of the fundamental
building blocks of OOP.
This is the most basic check. A class is a blueprint, a template, or a user-defined data type. It defines
attributes and methods but does not consume memory itself.4 An
object is a concrete instance of a class. When an object is created (instantiated), memory is allocated for
it in the heap, and it has its own state and can perform the behaviors defined in the class. 4
Constructors: A constructor is a special method that is automatically called when an object is created.
Its primary purpose is to initialize the object's state (i.e., its member variables). 13
o Rules: A constructor must have the same name as the class and does not have a return type. 14
o Types: Interview questions may ask about different types of constructors, especially in C++ 9:
Default Constructor: A constructor that takes no arguments. If no constructor is explicitly defined, the
compiler often provides one.
Parameterized Constructor: A constructor that accepts arguments to initialize the object with specific
values.
Copy Constructor: A constructor that creates a new object as a copy of an existing object. This is
crucial for understanding the difference between shallow and deep copies.18
Destructors: A destructor is a special method that is automatically called when an object is destroyed or
goes out of scope. Its purpose is to perform cleanup tasks, such as releasing resources (memory, file
handles, network connections) that the object acquired during its lifetime.14 In languages with automatic
garbage collection like Java, the concept is less direct. The
finalize() method in Java is similar but not a true destructor; it is called by the garbage collector
before reclaiming an object's memory, but its execution is not guaranteed.14
Access Specifiers (Modifiers)
As mentioned under Encapsulation, access specifiers are keywords that control the visibility and
accessibility of classes, methods, and attributes. Mastering them is essential for demonstrating an
understanding of proper OOP design. The main types are 7:
static: The static keyword indicates that a member (variable or method) belongs to the class itself,
rather than to any specific instance (object) of the class. A static variable is shared among all objects
of the class. A static method can be called without creating an object of the class.5 A common
interview question is why
main is static in Java: so the JVM can call it without having to create an instance of the main class
first.13
virtual: In C++, the virtual keyword is used in a base class to declare a function that can be
overridden in a derived class. It is the cornerstone of runtime polymorphism, signaling to the compiler
to use dynamic dispatch to resolve the method call at runtime based on the object's actual type, not the
reference type.5
final (Java) / sealed (C#): The final keyword in Java has multiple uses. A final variable is a
constant. A final method cannot be overridden. A final class cannot be inherited.13 The
sealed keyword in C# serves the same purpose for classes and methods.
super (Java) / base (C#): This keyword is used within a subclass to refer to its immediate superclass. It
can be used to call a superclass's constructor or to access an overridden method from the superclass.5
this: This keyword is a reference to the current object instance. It is used to differentiate between
instance variables and local variables (e.g., in a constructor: this.name = name;) or to pass the
current object as an argument to another method.13
Senior-level interviews move beyond definitions into the realm of design principles and practical trade-
offs. Candidates are expected to discuss not just how to use OOP features, but when and, more
importantly, when not to.
Advanced Concepts
SOLID Principles: While a deep dive is beyond the scope of many interviews, being able to name and
briefly explain the five SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution,
Interface Segregation, Dependency Inversion) signals a mature understanding of object-oriented
design.15
Design Patterns: These are reusable solutions to commonly occurring problems within a given context
in software design. Interviewers may ask about a few common ones to gauge practical design experience
15:
o Singleton: Ensures a class has only one instance and provides a global point of access to it.
o Factory: Creates objects without exposing the instantiation logic to the client, referring to the newly
created object through a common interface.
o Observer: Defines a one-to-many dependency between objects so that when one object changes state,
all its dependents are notified and updated automatically.
Coupling and Cohesion: These are metrics for design quality. Good design aims for low coupling
(modules are independent of each other) and high cohesion (elements within a single module are
closely related and focused on a single task).5
Asking about the limitations of OOP concepts is a sophisticated way to differentiate between academic
knowledge and battle-tested experience. A candidate who has only read textbooks will praise inheritance
as a tool for reuse. A candidate who has maintained a large, legacy codebase will be able to speak
eloquently about its pitfalls. This discussion demonstrates maturity and an understanding that all design
choices involve trade-offs.
Limitations of Inheritance: While powerful, inheritance has drawbacks. It creates a tight coupling
between the superclass and subclass; changes to the superclass can have unintended consequences for all
its descendants. Over time, deep inheritance hierarchies can become inflexible and difficult to
maintain.5 This is why modern design often prefers composition over inheritance.
Limitations of OOP in General: OOP is not a silver bullet. For very small, simple problems, the
overhead of defining classes and objects can be unnecessary (Not Ideal for Small Problems).5
OOP systems can also be complex, requiring
extensive planning and thorough testing to ensure all the interacting parts work correctly.5
A common interview tactic is to present a short piece of code and ask for its output. These problems are
designed to test a deep, precise understanding of language mechanics that definitions alone cannot
capture.
Constructor Call Order: In multiple inheritance (C++), base class constructors are called in the order
they are listed in the derived class's inheritance declaration, from left to right, before the derived class
constructor is executed.6 In multilevel inheritance, the call order proceeds from the topmost base class
downwards.
Virtual Base Classes and Object Size: A classic C++ question involves a "diamond" inheritance
structure where DerivedClass inherits from DerivedBaseClass1 and DerivedBaseClass2, both of
which inherit from a common BaseClass. Without using virtual inheritance, the DerivedClass
object will contain two separate copies of the BaseClass members, leading to ambiguity and wasted
space. Declaring the inheritance from BaseClass as virtual ensures that only one copy of the base
class members exists in the final derived object, which can be tested by asking for the
sizeof(DerivedClass).6
Method Resolution in a Hierarchy: Given a multilevel inheritance chain (e.g., C inherits from B,
which inherits from A), a call to a method like c.print() will be resolved by searching up the
hierarchy. The first implementation found is the one that gets executed. If B overrides print() from A,
and C does not, then B's version will be called.6
This is a common starting point. A candidate must articulate the evolution of data management.
Traditional File Systems: These are the most basic form of data storage. However, they suffer from
significant problems, including data redundancy (the same data duplicated in multiple files), data
inconsistency (updates not being propagated everywhere), difficulty in accessing data (no query
language), lack of concurrency control (multiple users cannot safely modify data at the same time), and
poor data integrity and security.1
DBMS (Database Management System): A DBMS is software designed to solve the problems of file
systems. It provides a centralized system for managing data with features like a query interface,
concurrency control, backup and recovery, and security mechanisms.1 Examples of DBMS that are not
strictly relational include XML databases or older hierarchical systems. 1
RDBMS (Relational Database Management System): An RDBMS is a specific type of DBMS based
on the relational model, introduced by E.F. Codd. In an RDBMS, data is stored in tables (also called
relations), which consist of rows (tuples) and columns (attributes). The relationships between data are
maintained through the data values themselves, primarily using keys. This is the dominant model for
structured data today. Examples include MySQL, PostgreSQL, Oracle DB, and SQL Server. 1
Database Languages
A DBMS provides specialized languages for different tasks. Understanding their roles is crucial.
DDL (Data Definition Language): Used to define and manage the database schema (the structure of
the database). Commands include CREATE (to make a new table, view, or index), ALTER (to modify an
existing structure), and DROP (to delete a structure).22
DML (Data Manipulation Language): Used to interact with the data within the tables. Commands
include SELECT (to retrieve data), INSERT (to add new rows), UPDATE (to modify existing rows), and
DELETE (to remove rows).22
DCL (Data Control Language): Used to manage user permissions and access control. Commands
include GRANT (to give permissions) and REVOKE (to take permissions away).22
TCL (Transaction Control Language): Used to manage transactions in the database. Commands
include COMMIT (to save the changes of a transaction) and ROLLBACK (to undo the changes of a
transaction).22
To provide users with an abstract view of the data and hide storage details, DBMSs use three levels of
abstraction 1:
1. Physical Level: The lowest level, describing how the data is actually stored. It deals with complex low-
level data structures, file organization, and storage details.
2. Logical Level (or Conceptual Level): The next level up, describing what data is stored in the database
and what relationships exist among that data. The entire database is described in terms of a small
number of relatively simple structures. Database administrators work at this level.
3. View Level: The highest level, describing only a part of the entire database relevant to a particular user
or group of users. It provides a simplified interface and can be used for security purposes by hiding
sensitive data.
Effective database design is critical for data integrity, performance, and maintainability. Interview
questions in this area focus on the E-R model, keys, and normalization.
Entity-Relationship (E-R) Model
The E-R model is a high-level conceptual data model used to design databases. It provides a graphical
representation of the logical structure.
Entity: A real-world object or concept about which data is stored (e.g., Student, Course).23
Attribute: A property or characteristic of an entity (e.g., StudentName, CourseID).25
Relationship: An association among two or more entities. Relationships have a cardinality that
specifies how many instances of one entity can be related to instances of another 2:
o One-to-One (1:1): A student can have only one student ID, and that ID belongs to only one student.
o One-to-Many (1:M): One professor can teach many courses, but a course is taught by only one
professor.
o Many-to-Many (M:N): A student can enroll in many courses, and a course can be taken by many
students. This type of relationship is typically implemented using a "junction" or "linking" table.
Database Keys
Keys are fundamental to the relational model, used to uniquely identify records and establish
relationships between tables. A candidate must have a precise understanding of each type.1
Super Key: A set of one or more attributes that, taken collectively, can uniquely identify a tuple (row)
in a relation.
Candidate Key: A minimal super key, meaning it's a super key from which no attribute can be removed
without it losing its uniqueness property. A relation can have multiple candidate keys.
Primary Key: One of the candidate keys that is chosen by the database designer to be the main
identifier for the relation. A primary key cannot contain NULL values and there can be only one primary
key per table.2
Alternate Key: A candidate key that was not chosen to be the primary key.
Foreign Key: A set of attributes in one table that refers to the primary key of another table. It is the
mechanism used to link tables and enforce referential integrity.22
Composite Key: A primary key that consists of two or more attributes.
Normalization
Normalization is the process of organizing columns and tables in a relational database to minimize data
redundancy and improve data integrity. It involves dividing larger tables into smaller, well-structured
tables and defining relationships between them. This helps prevent insertion, update, and deletion
anomalies.2
First Normal Form (1NF): The table must have a primary key, and all attributes must be atomic,
meaning each cell contains a single, indivisible value. There should be no repeating groups.
Second Normal Form (2NF): The table must be in 1NF, and all non-key attributes must be fully
functionally dependent on the entire primary key. This rule applies to tables with composite primary
keys; it prevents partial dependencies.
Third Normal Form (3NF): The table must be in 2NF, and there should be no transitive
dependencies. A transitive dependency exists when a non-key attribute depends on another non-key
attribute, which in turn depends on the primary key.
Boyce-Codd Normal Form (BCNF): A stricter version of 3NF. For any non-trivial functional
dependency X→Y, X must be a super key. Most tables in 3NF are also in BCNF.
Denormalization
Denormalization is the strategic process of introducing redundancy back into a normalized database.
While normalization is crucial for data integrity, it can sometimes lead to complex queries that require
many joins, which can be slow. Denormalization is a performance optimization technique where data
from multiple tables is combined into one to reduce the need for joins and speed up data retrieval, at the
cost of increased storage and a higher risk of data anomalies. 25 This is a common trade-off in data
warehousing and reporting systems.
It is a mistake to study keys, normalization, and joins as isolated topics. They form a deeply
interconnected system that defines the relational model. An interviewer's questions often traverse these
concepts to gauge a candidate's holistic understanding.
1. The process begins with identifying real-world entities and their relationships.
2. Keys are then defined to give these entities unique identities (Primary Keys) and to represent the
relationships between them (Foreign Keys).
3. Normalization is the formal process of structuring the tables around these keys to eliminate
redundancy. A many-to-many relationship, for example, is normalized by creating a junction table that
contains foreign keys to the two related entities.
4. Once the data is logically separated into normalized tables, Joins become the essential DML mechanism
to bring that related data back together to answer meaningful questions.
A superior interview answer demonstrates this interconnectedness. When asked to define a foreign key,
a good answer states it's a key that references a primary key in another table. A great answer adds that
this key is the lynchpin for performing a JOIN operation, which is necessary to reconstruct information
that was deliberately separated during the process of normalization to ensure data integrity. This shows
an understanding of not just the "what" but the "why" of relational database design.
Structured Query Language (SQL) is the standard language for interacting with relational databases.
Proficiency in SQL is a hard requirement for almost any backend or data-focused role.
Core Queries
SELECT, FROM, WHERE: The basic structure for retrieving data. SELECT specifies the columns, FROM
specifies the table, and WHERE filters rows based on a condition.
GROUP BY: Groups rows that have the same values in specified columns into summary rows. It is often
used with aggregate functions.
HAVING: Filters the results of a GROUP BY clause. The critical difference, and a classic interview
question, is that WHERE filters rows before any grouping or aggregation occurs, while HAVING filters
groups after aggregation has been performed.27
ORDER BY: Sorts the final result set in ascending (ASC) or descending (DESC) order.
Joins
Joins are used to combine rows from two or more tables based on a related column.
INNER JOIN: Returns only the rows where the join condition is met in both tables. This is the most
common type of join.2
OUTER JOIN:
o LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table, and the matched rows from
the right table. If there is no match, the columns from the right table will have NULL values.2
o RIGHT JOIN (or RIGHT OUTER JOIN): The inverse of a LEFT JOIN. Returns all rows from the right
table and matched rows from the left.
o FULL OUTER JOIN: Returns all rows when there is a match in either the left or the right table. It
combines the functionality of LEFT and RIGHT joins.
CROSS JOIN: Returns the Cartesian product of the two tables, meaning every row from the first table is
combined with every row from the second table.21
SELF JOIN: A regular join, but the table is joined with itself. This is useful for querying hierarchical
data stored in a single table, such as an employee table where each employee has a ManagerID that
refers to another employee's EmployeeID in the same table.21
Advanced SQL
Subqueries (Nested Queries): A query placed inside another query. They can be used in SELECT,
FROM, WHERE, or HAVING clauses. A correlated subquery is a subquery that depends on the outer query
for its values. It is evaluated once for each row processed by the outer query, which can be inefficient. 2
Views: A virtual table based on the result-set of an SQL statement. A view contains rows and columns,
just like a real table, but it does not store data physically. Views are used to simplify complex queries,
provide a level of security by restricting access to data, and present data in a specific way.2
Indexes: A special lookup table that the database search engine can use to speed up data retrieval. An
index improves the speed of SELECT queries and WHERE clauses but adds overhead to data modification
(INSERT, UPDATE, DELETE) because the index must also be updated.21
Triggers: A special type of stored procedure that automatically executes in response to certain events
on a particular table (e.g., after an INSERT, UPDATE, or DELETE). Triggers are often used to maintain
data integrity or enforce complex business rules.25
Stored Procedures: A set of pre-compiled SQL statements that can be saved and reused. They improve
performance by reducing network traffic and allow for modular programming and better security. 25
Set Operations
UNION vs. UNION ALL: Both are used to combine the result sets of two or more SELECT statements. The
key difference is that UNION removes duplicate rows from the combined result set, whereas UNION ALL
includes all rows, including duplicates. Because UNION has to do the extra work of identifying and
removing duplicates, UNION ALL is significantly faster and should be used if duplicates are acceptable
or known not to exist.2
ACID Properties
A transaction is a single logical unit of work, which may consist of multiple operations. To ensure data
integrity, transactions must adhere to the ACID properties. This is a critical concept for any database
interview.1
Atomicity: Ensures that a transaction is treated as a single, indivisible unit. It either executes completely
or not at all ("all or nothing"). If any part of the transaction fails, the entire transaction is rolled back.
Consistency: Guarantees that a transaction brings the database from one valid state to another. All data
integrity constraints must be satisfied.
Isolation: Ensures that concurrently executing transactions do not interfere with each other. The
intermediate state of one transaction should not be visible to other transactions. This is achieved through
locking mechanisms.
Durability: Guarantees that once a transaction has been committed, its changes are permanent and will
survive any subsequent system failure (e.g., power loss or crash). This is typically achieved by writing
to a transaction log.23
Concurrency Issues
Deadlock: A situation where two or more transactions are waiting indefinitely for each other to release
locks. For example, Transaction 1 locks Resource A and waits for Resource B, while Transaction 2
locks Resource B and waits for Resource A. DBMSs can prevent deadlocks or detect and resolve them,
usually by aborting one of the transactions.27
Locking
Locking is the primary mechanism for achieving isolation and controlling concurrency.
Shared Lock (Read Lock): Allows multiple transactions to read the same data item concurrently. Other
transactions can acquire a shared lock on the item, but no transaction can acquire an exclusive lock until
all shared locks are released.
Exclusive Lock (Write Lock): When a transaction needs to write (update, insert, or delete) a data item,
it must acquire an exclusive lock. An exclusive lock prevents any other transaction (read or write) from
accessing the item until the lock is released.1
This is a highly practical question that tests a candidate's understanding of the underlying database
engine's behavior, not just SQL syntax. The differences are crucial for performance, security, and
recoverability.2
Feature DELETE TRUNCATE DROP
Command DML (Data Manipulation DDL (Data Definition DDL (Data Definition
Type Language) Language) Language)
Fires DELETE triggers for each Does not fire any DELETE Does not fire any
Triggers
affected row. triggers. triggers.
OSI (Open Systems Interconnection) Model: A 7-layer conceptual model that provides a standard for
different computer systems to communicate with each other. While not implemented directly in practice,
its terminology is widely used, and it serves as an excellent educational tool for understanding the
different functions involved in networking. 32 The layers are:
7. Application: The human-computer interaction layer, where applications can access network services.
6. Presentation: Ensures that data is in a usable format and is where data encryption occurs.
5. Session: Maintains connections and is responsible for controlling ports and sessions.
3. Network: Responsible for packet forwarding, including routing through different routers.
2. Data Link: Provides node-to-node data transfer and handles error correction from the physical layer.
1. Physical: Responsible for the physical connection between devices and the transmission of raw bit
streams.3
TCP/IP Model: A 4-layer or 5-layer model that is the practical foundation of the modern internet. It is
more descriptive of the actual protocols used. A common 4-layer representation includes 33:
1. Application Layer: Combines the functions of the OSI Application, Presentation, and Session layers.
(Protocols: HTTP, FTP, DNS, SMTP).
2. Transport Layer: Corresponds to the OSI Transport layer. (Protocols: TCP, UDP).
3. Internet Layer (or Network Layer): Corresponds to the OSI Network layer. (Protocols: IP, ICMP,
ARP).
4. Network Access Layer (or Link Layer): Combines the functions of the OSI Data Link and Physical
layers. (Protocols: Ethernet, Wi-Fi).
Encapsulation
Encapsulation is the process of adding protocol-specific headers (and sometimes trailers) to data as it
travels down the network stack from the Application layer to the Physical layer. At each layer, the entire
payload from the layer above is treated as data and wrapped with a new header. For example, the
Transport layer takes application data and adds a TCP header to create a "segment." The Network layer
takes this segment and adds an IP header to create a "packet." The Data Link layer takes this packet and
adds an Ethernet header and trailer to create a "frame." This process is reversed (decapsulation) on the
receiving end.32
Understanding the differences between these two models is a fundamental networking question. A
comparative table is an effective way to summarize the key points.3
Feature OSI Model TCP/IP Model
Number of
7 Layers 4 or 5 Layers
Layers
Feature OSI Model TCP/IP Model
Vertical approach. The model was defined Horizontal approach. The protocols were
Approach
before the protocols. defined before the model.
Protocol
Protocol independent. Protocol dependent.
Dependency
Primarily a conceptual and reference model The practical model on which the modern
Usage
for teaching and understanding. internet is built.
While the layered models provide the framework, the protocols are the specific sets of rules that govern
communication.
TCP (Transmission Control Protocol): This is a connection-oriented protocol. Before data is sent, a
reliable connection is established using a three-way handshake (SYN, SYN-ACK, ACK).35 TCP provides
reliable, ordered delivery of a stream of bytes. It includes mechanisms for error checking (checksums),
flow control (to prevent overwhelming the receiver), and congestion control (to manage network
traffic). This reliability comes at the cost of higher overhead and slower speed. It is used for applications
where data integrity is paramount, such as web browsing (HTTP), file transfer (FTP), and email
(SMTP).35
UDP (User Datagram Protocol): This is a connectionless protocol. It sends packets (datagrams)
without establishing a prior connection. It is unreliable and does not guarantee delivery, order, or error
checking beyond a basic checksum. Its advantage is its low overhead and high speed. It is used for
applications that are latency-sensitive and can tolerate some packet loss, such as video and audio
streaming, online gaming, and DNS lookups. 35
DNS (Domain Name System): Often called the "phonebook of the internet," DNS is the protocol that
translates human-readable domain names (e.g., www.google.com) into machine-readable IP addresses
(e.g., 172.217.14.238). This process is called resolution. DNS queries are typically sent over UDP for
speed, as a lost query can simply be re-sent.3
HTTP (Hypertext Transfer Protocol): The foundation of data communication for the World Wide
Web. It is a client-server protocol used for fetching resources, such as HTML documents. It operates on
top of TCP to ensure reliable delivery of web content.
HTTPS (HTTP Secure): This is an extension of HTTP that adds a layer of security. It uses SSL
(Secure Sockets Layer) or its successor, TLS (Transport Layer Security), to encrypt the
communication between the client and server. This encryption provides confidentiality (preventing
eavesdropping) and integrity (preventing data tampering).3
IP (Internet Protocol): The principal communications protocol in the Internet protocol suite for
relaying datagrams across network boundaries. Its routing function enables internetworking and
essentially establishes the Internet. IP is responsible for logical addressing—assigning a unique IP
address to each device on a network—and for routing packets from a source host to a destination host,
possibly across multiple networks.32 A key interview topic is the difference between IPv4 (a 32-bit
address space, nearly exhausted) and IPv6 (a 128-bit address space, providing a vastly larger number of
addresses).32
ARP (Address Resolution Protocol): A protocol used to find the hardware address (MAC address) of a
device from its known IP address. When a host wants to send a packet to another host on the same local
network, it knows the destination IP address but needs the destination MAC address to create the
Ethernet frame. The source host broadcasts an ARP request packet containing the target IP address. The
host on the network that has that IP address replies with an ARP response containing its MAC address. 32
Many individual networking questions can be unified by a single, comprehensive scenario: "What
happens when you type google.com into your browser and press Enter?" A strong candidate can
narrate this entire journey, demonstrating a holistic understanding of how the layers and protocols work
together.
This section covers the physical and logical components that make up a network.
Network Devices
Understanding the function of key network devices and the layer at which they operate is fundamental.
Hub: A Layer 1 (Physical) device. It is a simple repeater that broadcasts any incoming data packet to all
of its ports. All devices connected to a hub are in the same collision domain (meaning if two devices
transmit at once, their signals collide and become garbled) and the same broadcast domain.32
Switch: A Layer 2 (Data Link) device. A switch is more intelligent than a hub. It learns the MAC
addresses of the devices connected to its ports and maintains a MAC address table. When a frame
arrives, the switch looks at the destination MAC address and forwards the frame only to the specific port
connected to that destination device. This means each port on a switch is its own collision domain,
significantly improving efficiency. However, all ports are still in the same broadcast domain.32
Router: A Layer 3 (Network) device. A router's primary function is to connect different networks
together and forward packets between them based on their IP addresses. Routers use routing tables to
determine the best path for a packet to reach its destination. Crucially, routers do not forward broadcast
traffic by default, meaning they are used to break up broadcast domains.32
Addressing
MAC (Media Access Control) Address: A 48-bit, globally unique hardware address that is burned into
a device's Network Interface Card (NIC) by the manufacturer. It operates at the Data Link layer and is
used for communication within a single local network segment. 32
IP (Internet Protocol) Address: A logical address assigned to a device on a network. It operates at the
Network layer and is used for communication across different networks (i.e., on the internet).
o Classes: IPv4 addresses were historically divided into classes (A, B, C, D, E) to accommodate networks
of different sizes, though this system has been largely replaced by Classless Inter-Domain Routing
(CIDR).36
o Private vs. Public IP: Private IP addresses (e.g., 192.168.x.x, 10.x.x.x) are used within a local network
and are not routable on the public internet. Public IP addresses are globally unique and assigned by
Internet Service Providers (ISPs).32
o Subnet Mask: A subnet mask is a 32-bit number that divides an IP address into its network and host
portions. This allows a large network to be broken down into smaller, more manageable subnetworks
(subnets).32
Fundamental Security
Firewall: A network security device that monitors and filters incoming and outgoing network traffic
based on an organization's predefined security policies. It acts as a barrier between a trusted internal
network and an untrusted external network, such as the internet.3
NAT (Network Address Translation): A method used by routers to map multiple private IP addresses
within a local network to a single public IP address before transferring the information onto the internet.
This conserves the limited supply of public IPv4 addresses and provides a layer of security by hiding the
internal network's structure from the outside world.32
VPN (Virtual Private Network): A technology that creates a safe and encrypted connection over a less
secure network, such as the public internet. A VPN can be used to securely connect to a remote
corporate network, effectively creating a private "tunnel" for data that protects it from eavesdropping.36
Part IV: A Practitioner's Handbook for Data Structures & Algorithms (DSA)
The Data Structures and Algorithms (DSA) portion of a technical interview is where a candidate's
problem-solving and coding skills are most directly tested. Success in this area is not about memorizing
hundreds of solutions but about understanding fundamental data structures, recognizing algorithmic
patterns, and being able to analyze the efficiency of a proposed solution.
Before diving into specific problems, it is essential to have a firm grasp of the language used to discuss
algorithm efficiency: Big O notation. Asymptotic analysis provides a high-level way to describe an
algorithm's runtime and space requirements as the input size grows. 41
Time Complexity: Measures how the runtime of an algorithm grows with the size of the input (n).
Space Complexity: Measures how the amount of extra memory or space required by an algorithm
grows with the size of the input.
O(1) (Constant): The runtime is constant, regardless of the input size (e.g., accessing an array element
by index).
O(logn) (Logarithmic): The runtime grows logarithmically. The algorithm typically halves the search
space with each step (e.g., binary search).
O(n) (Linear): The runtime grows linearly with the input size. The algorithm touches each element once
(e.g., finding an item in an unsorted array).
O(nlogn) (Log-Linear): The typical complexity for efficient comparison-based sorting algorithms (e.g.,
Merge Sort, Heap Sort).
O(n2) (Quadratic): The runtime grows quadratically. The algorithm typically involves nested loops over
the input (e.g., Bubble Sort, Selection Sort).
O(2n) (Exponential): The runtime doubles with each addition to the input size. Often seen in brute-force
recursive solutions.
For each data structure, a candidate should know its core concept, the time and space complexity of its
key operations, and the canonical interview problems that test its application.
Concept: An array is a collection of items stored at contiguous memory locations. A string is often
implemented as an array of characters.18
Complexity:
o Access: O(1)
o Search: O(n)
o Insertion/Deletion: O(n) (because subsequent elements may need to be shifted).
Canonical Problems:
o Two Sum: Given an array of integers, find two numbers that add up to a specific target. (A classic
problem to introduce hash maps for an O(n) solution).45
o Best Time to Buy and Sell Stock: Find the maximum profit that can be achieved from one
transaction.45
o Container With Most Water: Find two lines that together with the x-axis form a container that holds
the most water. (Tests the two-pointer pattern).45
o Longest Substring Without Repeating Characters: Find the length of the longest substring without
repeating characters. (Tests the sliding window pattern).45
Linked Lists
Concept: A linear data structure where elements are not stored contiguously but are linked using
pointers. Each element (node) contains data and a reference to the next node. Key variations include
Singly Linked Lists (one-way pointers) and Doubly Linked Lists (pointers to both the next and previous
nodes).41
Complexity:
o Access/Search: O(n)
o Insertion/Deletion (at head): O(1)
o Insertion/Deletion (at tail/middle): O(n) to find the position, O(1) to perform the operation once the node
is found.
Canonical Problems:
o Reverse a Linked List: Iteratively or recursively reverse the pointers.45
o Detect Cycle in a Linked List: Use the "Floyd's Tortoise and Hare" (two-pointer) algorithm. 45
o Merge Two Sorted Lists: Combine two sorted lists into a single sorted list.45
o Remove Nth Node From End of List: Use a two-pointer approach with a fixed gap. 45
Concept:
o Stack: A Last-In, First-Out (LIFO) data structure. Operations are push (add to top) and pop (remove
from top).18
o Queue: A First-In, First-Out (FIFO) data structure. Operations are enqueue (add to rear) and dequeue
(remove from front).18
Complexity:
o All primary operations (push, pop, enqueue, dequeue, peek) are O(1).
Canonical Problems:
o Valid Parentheses: Use a stack to check if a string of parentheses is balanced.45
o Implement Queue using Stacks: Use two stacks to simulate FIFO behavior. 41
o Min Stack: Design a stack that supports push, pop, top, and retrieving the minimum element in
constant time.
Concept: A data structure that maps keys to values for highly efficient lookup. It uses a hash function
to compute an index into an array of buckets or slots, from which the desired value can be found. A key
interview topic is collision resolution—how to handle cases where two different keys hash to the same
index. Common strategies are chaining (each bucket is a linked list) and open addressing (probing for
the next empty slot).18
Complexity:
o Access/Search/Insertion/Deletion (Average Case): O(1)
o Access/Search/Insertion/Deletion (Worst Case): O(n) (if all keys collide into one bucket).
Canonical Problems:
o Two Sum (Optimal Solution): The most efficient solution uses a hash map to store numbers seen so far
and check if target - current_number exists in the map.
o Group Anagrams: Group words that are anagrams of each other. (The key can be the sorted version of
the word).
o Finding Duplicates: An efficient way to check for duplicates in an array is to iterate through it and use
a hash set to track elements that have been seen.
Trees
Concept: A specialized tree-based data structure that satisfies the heap property. In a Min-Heap, the
key of any node is less than or equal to the keys of its children. In a Max-Heap, the key of any node is
greater than or equal to the keys of its children. This structure makes it very efficient to find the
minimum or maximum element. Heaps are the most common way to implement a priority queue. 18
Complexity:
o Find Min/Max: O(1)
o Insert/Delete Min/Max: O(logn)
Canonical Problems:
o Top K Frequent Elements: Use a hash map to count frequencies and a min-heap of size K to keep
track of the top K elements.45
o Find Median from Data Stream: Use two heaps (a max-heap for the lower half and a min-heap for the
upper half) to keep the data balanced and find the median in O(logn) time.45
o Merge K Sorted Lists: Use a min-heap to efficiently find the smallest element among the heads of all
K lists.45
Graphs
Concept: A data structure consisting of a set of vertices (nodes) and a set of edges that connect pairs of
vertices.
o Representations: Adjacency List (an array of lists, where each index corresponds to a vertex and the
list contains its neighbors) is usually preferred for sparse graphs. Adjacency Matrix (a 2D array where
matrix[i][j] = 1 if there is an edge from vertex i to j) is better for dense graphs.
o Traversal Algorithms: These are fundamental. Breadth-First Search (BFS) explores neighbors level
by level and uses a queue. Depth-First Search (DFS) explores as far as possible along each branch
before backtracking and uses a stack (often implicitly via recursion). 18
Canonical Problems:
o Number of Islands: A classic problem of traversing a 2D grid (which can be modeled as a graph) using
BFS or DFS to count connected components. 41
o Clone Graph: Create a deep copy of a graph. Requires traversing the graph while keeping track of
visited nodes to avoid infinite loops, often using a hash map.45
o Course Schedule: Given prerequisites, determine if all courses can be taken. This is a classic
application of Topological Sort on a directed acyclic graph (DAG).45
o Pacific Atlantic Water Flow: Find all grid cells from which water can flow to both the Pacific and
Atlantic oceans. Solved by starting BFS/DFS from the ocean borders and working inwards. 45
The most effective way to prepare for DSA interviews is not to solve hundreds of random problems, but
to master fundamental algorithmic patterns. The canonical problems listed above are not important in
themselves, but because they are exemplars of these patterns. An interviewer tests for pattern
recognition. A strong candidate sees a problem, identifies the underlying pattern, and maps it to a known
algorithmic template.
"Number of Islands" is not just a grid problem; it is a test of Graph Traversal (BFS/DFS) on an
implicit graph.
"Course Schedule" is not just about courses; it is a test of Topological Sort for any problem involving
dependencies in a directed acyclic graph.
"Container With Most Water" is a classic Two-Pointer problem.
"Longest Substring with K Distinct Characters" is a test of the Sliding Window pattern.
"LRU Cache" is a famous problem that tests the ability to combine data structures (a hash map for
O(1) lookup and a doubly linked list for O(1) eviction).41
By focusing on these patterns, a candidate develops a versatile toolkit that can be adapted to a wide
variety of unfamiliar problems, which is the true skill being assessed.
Sorting: While you may not be asked to implement a sorting algorithm from scratch, you must know
their properties and trade-offs.
Searching: Binary Search is a mandatory algorithm. It is an efficient (O(logn)) method for finding an
element in a sorted array by repeatedly dividing the search interval in half.44
Time Complexity Time Complexity Space Complexity
Algorithm Stable
(Average) (Worst) (Worst)
Selection
O(n2) O(n2) O(1) No
Sort
Insertion
O(n2) O(n2) O(1) Yes
Sort
Recursion
Recursion is the technique of a function calling itself. A recursive solution must have a base case (a
condition to stop the recursion) and a recursive step (the part that moves closer to the base case). Many
tree and graph traversal problems, as well as divide-and-conquer algorithms, have elegant recursive
solutions.42
DP is an advanced technique for solving problems by breaking them down into simpler, overlapping
subproblems. The results of subproblems are stored (memoization) or built up (tabulation) to avoid
redundant computation.
Key Idea: Identify overlapping subproblems and an optimal substructure (the optimal solution to the
problem can be constructed from optimal solutions of its subproblems).
Classic Examples: Calculating the nth Fibonacci number, the Knapsack problem, and finding the
Longest Common Subsequence. 42
In advanced rounds, particularly System Design interviews, these topics converge. Designing a service
like a social media feed or a URL shortener requires applying all four pillars. You will use OOP
principles to design the classes and components of your system. You will need a deep understanding of
DBMS to choose the right database (SQL vs. NoSQL), design the schema, and consider trade-offs
between normalization and performance. Your design will depend on Computer Networking concepts
to handle scalability, latency, and data transfer, involving load balancers, CDNs, and various protocols.
Finally, the core logic of your components will be built upon the efficient use of Data Structures and
Algorithms—for example, using a graph database to model social connections or a specific algorithm to
generate unique shortened URLs.
Preparation should therefore focus not only on the individual questions within each domain but on
building mental bridges between them. Understand that a choice in database schema (DBMS) affects the
queries you can run, which in turn affects the API design of your backend service (OOP), which must be
resilient to network failures (CN) and perform its logic efficiently (DSA).
Ultimately, success in a technical interview is a signal of your ability to become a productive and
thoughtful engineer. It requires more than correct answers; it requires clear communication, a
demonstrated understanding of trade-offs, and a robust, interconnected knowledge of computer science
fundamentals. By using this guide to build that deep understanding, you will be well-equipped to
navigate the challenges of the modern technical interview and demonstrate your potential as a valuable
member of any engineering team.