Computer Science Interview Questions
Computer science is a broad field of study that deals with the design, analysis, and implementation of computer systems. It is a subfield of computer engineering, that deals with the design and construction of computers and computer systems.
Computer science is a growing field, with new technologies and applications being developed every day. As a result, there is a need for new education programs that can prepare students for the future. In order to be successful in this field, students need to be well-versed in mathematics and computer science concepts. They also need to be familiar with software development techniques and be able to troubleshoot problems when they arise. Finally, they need to be able to think critically and be able to problem-solve.
Computer science is a fast-growing field that has many opportunities for career growth. A Computer Science interview is a type of interview that is designed to assess a candidate's knowledge of computer science. The purpose of the interview is to evaluate the candidate's knowledge and understanding of computer science concepts, including programming and data structures & algorithms. The interview may also assess the candidate's communication skills, such as the ability to present complex information in a clear and concise manner.
The Interview is typically conducted by a hiring manager or recruiter who has experience in the field. The interviewer will typically ask a series of questions about the candidate's background and experience. The interviewer will also ask about the candidate's strengths and weaknesses.
In this article, we’ll discuss the common interview questions that prospective programmers may face. This will give you an idea of what to expect from interviews and help you prepare for them. If you are preparing for an engineering or computer science job, then this article is for you! Be sure to review computer science interview questions for freshers as well as experienced candidates to land the job you desire.
Computer Science Interview Questions for Freshers
1. Explain the computer system?
The computer system is the collection of hardware and software that makes up a computer. It consists of the processor, memory, storage devices, input/output devices, and other components.
- The processor is the central processing unit (CPU) that processes information and controls the computer’s operations.
- The memory is the computer’s temporary storage area.
- The storage devices are used to store data and programs.
- The input/output devices are used to connect the computer to external devices such as printers, keyboards, and mice.
- The computer system is a complex device that has many functions. It is used to store and process information, communicate with other computers and other devices, and perform calculations.

2. What is a file?
A file is a collection of data that is stored on a computer or other device. Files can be text, images, sounds, or any combination of these. They can be stored on a computer, a hard drive, or some other device. When you open a file, you are actually opening a copy of the data inside the file. This copy is called the “file” and it is what you see when you open the file. The file can be opened in many different ways. For example, you can open it by clicking on it or by double-clicking on it. The file can also be opened by dragging and dropping it onto the screen or by using other methods. When you open a file, you are actually opening a copy of the data inside the file.
3. What is inheritance?
Inheritance is a way of structuring code so that it can be shared between different classes. Inheritance allows code to be shared between different classes and allows the same class to have different implementations in different contexts. Inheritance is a powerful tool that can make your code more maintainable and easier to understand. Inheritance is a fundamental concept in programming. It’s a way of structuring code so that it can be shared between different classes.

4. What is a chipset?
A chipset is a collection of circuit boards and other components that are used to connect a computer to the rest of the world. Chipsets are typically used to connect computers to the internet, printers, scanners, and other peripherals. Chipsets are also used to provide a way for computers to communicate with each other. For example, a chipset might be used to connect a computer to a printer or scanner. A chipset might also be used to communicate with other computers over the internet. Sockets are the most common type of chipset.
5. What is an operating system?
An operating system is a collection of software that runs on a computer and provides the basic functions of storing and managing information, such as memory, storage devices, and network access. The operating system controls how the computer works and how it interacts with other software and hardware. For example, an operating system can control the way a computer stores and accesses data, such as files and printers. In addition to controlling how the computer works and operating system can also provide many other functions, such as security, communication, and user interface. An operating system can also be used to develop new software applications.

Learn via our Video Courses
6. How many popular operating systems are in use today?
Operating systems are the software that controls the way a computer works. There are many different operating systems out there, and they all have different features and benefits. The most popular operating systems today are Windows, Mac OS, and Linux. Windows is the most popular because it is the most widely used operating system. It is also the most expensive, but it is also the most secure. Mac OS is another popular operating system that is easy to use and has a lot of features. Linux is a very popular operating system that is free and open-source, which means that anyone can use it. Linux is also very easy to use, so it is great for beginners.
7. What is a microprocessor?
A microprocessor is a computerized device that is small enough to fit in a computer’s memory. Microprocessors are used in many different kinds of devices, including computers, cell phones, and industrial robots. Microprocessors are very important because they allow computers to perform many different tasks. For example, microprocessors are used to control the flow of electricity in a computer. They also help computers store and retrieve information. Microprocessors are also used to create new products. For example, microprocessors are used to create new types of computers. They are also used to create new types of robots.
8. What is a class variable?
A class variable is a variable that is defined in a class and shared by all instances of the class. Class variables can be used to store information about an object, such as its name, its location in memory, and its state at any given time. Class variables are often used to store information that is shared by objects in the same class. For example, a class might have a variable called name that is shared by all instances of the class. Class variables are often created with the special keyword class.
9. What is a Software Development Life Cycle?
A software development life cycle (SDLC) is a process used to plan and manage the development of software. The SDLC is a set of activities that are performed over a period of time to ensure that the software is developed in a way that is efficient and effective. The SDLC can be divided into three phases: planning, design, and implementation. During the planning phase, the organization identifies the goals and objectives that need to be achieved. During the design phase, the organization identifies the requirements for the software that will be developed. During the implementation phase, the organization prepares the software for production and tests it to ensure that it meets all of its requirements. The SDLC is an important part of any software development process because it ensures that the software is developed in a way that is efficient and effective.

10. What is a programming language?
A programming language is a computer language designed to facilitate the creation of software. It is a set of rules and guidelines that govern the structure and format of computer programs. A programming language is typically a high-level language that abstracts away the complexities of programming in order to make it easier for programmers to understand and write code. There are many different programming languages, including C, C++, Java, and Python. The most popular programming languages today are C++ and Java. C++ is a high-level language that abstracts away the complexities of programming in order to make it easier for programmers to understand and write code.
11. What is Integrated Development Environment?
An integrated development environment (IDE) is a software tool that allows developers to create, edit, and debug their software in a single interface. IDEs are typically used by software developers who work on large projects. IDEs are typically used to create and edit source code, as well as to debug and test programs. IDEs are also used to create documentation, as well as to share code between different teams. IDEs are typically used to create and edit source code, as well as to debug and test programs. IDEs also allow developers to create and edit documentation.

12. Explain the framework in software development?
A framework is a collection of reusable components that can be used to build software. Frameworks are often used to structure large projects and to help teams work together. Frameworks are usually built using a set of reusable components. These components can be used to build different types of software, such as web applications, desktop applications, and mobile apps. A framework can be used to structure large projects and to help teams work together. A framework can also be used to help teams understand the different stages of software development. For example, a framework can help teams understand the different stages of software development when building web applications.

13. What is an Interface?
An interface is a way of communicating between two objects. The objects can be software or hardware. An interface can be defined in many different ways, but the most common definition is that it is a way for one object to talk to another object. This communication can take many different forms, such as sending data to the other object, receiving data from the other object, or both. An interface can be implemented in many different ways, but the most common way is to use a software class. This class defines the interface and then other classes can use this class to implement the interface. When an object uses an interface, it is saying that it understands how the interface works and can use it to communicate with other objects.
14. What is an abstract class?
An abstract class is a class that is not defined in the source code. Instead, it is defined in a file that contains a definition of the class. The file defines the class by defining all of the properties and methods of the class. However, the class does not have to be defined in the source code. Instead, it can be defined in a separate file that is included in the source code. The file can then be referenced by the source code. This allows the class to be abstract and still be defined in the source code. The main advantage of an abstract class is that it allows other classes to use the class without having to know all of its properties and methods. This makes it possible for other classes to use a class without knowing all of its properties and methods.
15. What is an array?
An array is a data structure that can hold a lot of data. Arrays are used in a lot of different applications, such as databases, spreadsheets, and games. Arrays are made up of different data types, such as numbers, strings, and characters. Arrays are also called indexed structures because they can be accessed by indexing. Arrays are one of the most important data structures in programming. They are used to store data in a way that is easy to access and to organize it in a way that makes sense. Arrays are also used in many different applications, such as databases, spreadsheets, and games. An array is a data structure that can hold a lot of data. Arrays are used in a lot of different applications, such as databases, spreadsheets, and games.
16. What is a constructor?
A constructor is a function that is called when an object is created. A constructor is a function that takes a few arguments the type of object to be created, the initial state of the object, and the name of the class that will contain the object. When an object is created, it is passed to the constructor of the class that contains the object. A constructor can be used in many different ways. For example, a constructor can be used to initialize an array of objects or to initialize a variable that will be used by multiple objects. In these cases, it is important to use a constructor that takes only a few arguments.

17. Define Cin and Cout in C++?
Cin and cout are two important functions in C++ that you should know about. Cin and cout are functions that allow you to read and write data to a stream. The basic syntax of cin and cout is as follows:
- cin(stream) - Read data from the stream.
- cin(stream, value) - Read data from the stream and assign a value to the variable.
- cout(stream) - Write data to the stream.
- cout(stream, value) - Write data to the stream and assign a value to the variable.
The first function cin takes a stream as an argument and reads data from the stream. The second function cout takes a stream as an argument and writes data to the stream. You can use cin and cout to read and write data from a file, a database, or any other source of data.
18. What is artificial intelligence?
Artificial intelligence (AI) is a branch of computer science that deals with the development of machines that can learn and process information. AI has applications in a wide range of fields, including robotics, machine learning, and artificial intelligence. In robotics, AI is used to build robots that can perform tasks that would be too difficult or dangerous for humans to perform. For example, AI could be used to build robots that can navigate through dangerous environments, such as mines or oil rigs. In machine learning, AI is used to train machines to recognize patterns and make decisions based on those patterns.

19. What is machine learning?
Machine learning is a field of computer science that deals with the identification and analysis of patterns in data. Machine learning algorithms can be used to identify patterns in data, such as relationships between variables, or to make predictions based on those relationships. Machine learning algorithms can be divided into two broad categories: supervised and unsupervised. Supervised machine learning algorithms, such as classification and regression, are used to identify patterns in data. Unsupervised machine learning algorithms, such as clustering and association analysis, are used to identify associations between variables. The most common supervised machine learning algorithms are classification and regression.

20. What is deep learning?
Deep learning is a field of computer science that focuses on building artificial neural networks that can learn from data. These networks can be used to perform tasks such as image recognition, speech recognition, and translation. Deep learning is a field of computer science that focuses on building artificial neural networks that can learn from data. These networks can be used to perform tasks such as image recognition, speech recognition, and translation. Deep learning has become a hot topic in recent years due to its potential applications in fields such as artificial intelligence, machine learning, and computer vision. In order to train a deep learning network, it is first necessary to create a model. A model is a representation of the data that the network is expected to learn from.
21. What are the different OOPS principles?
OOPS, principles are a set of rules and guidelines that organizations can use to ensure that their software is as bug-free as possible. The OOPS principles are:
- Open source- All software should be released under an open-source license, such as the GNU General Public License (GPL) or the Apache License.
- Patent- All software should be released with a patent waiver, such as the USPTO's Patent Promise or the EU's EPO.
- Quality- All software should be developed using quality-assured tools and practices, such as unit testing and code reviews.
- Simplicity- All software should be easy to understand and maintain, and should not require complex configuration or customization.
- Reuse- All software should be reusable so that it can be adapted to new needs without requiring a complete rewrite.
- Simplicity- All software should be easy to understand and maintain, and should not require complex configuration or customization.
22. Explain the access modifiers?
Access modifiers are a way of specifying which users have access to a resource. Access modifiers are often used to control access to data, files, or other resources. For example, a database might allow only certain users to see the data. Or, a file might be locked down so that only the owner can see it.
23. What do you mean by destructor?
A destructor is a function that is called when an object is destroyed. A destructor is a way to clean up after an object has been destroyed. When an object is destroyed, the memory associated with the object is released. When an object is created, the memory associated with the object is allocated. The destructor is called when the memory associated with the object is no longer needed. The destructor frees up the memory associated with the object and releases it into the environment. When an object is destroyed, it can be very difficult to find out why an object was destroyed.
24. What are the Layers of the OSI Model?
The OSI model is a system-level networking model that describes the topology of a network. The model consists of seven layers: Physical, Data Link, Transport, Network, Application, and Management. Each layer is responsible for providing a specific function. For example, the Physical layer provides connectivity between devices and the Data Link layer is responsible for data transmission. The Transport layer is responsible for routing data and the Network layer is responsible for managing the network. The Application layer is responsible for providing services to the devices on the network and the Management layer is responsible for managing the network. Each layer in the OSI model has a specific purpose and each layer in the OSI model has a specific role to play in the overall system.

25. What is the thread in programming?
The thread is a fundamental concept in programming. It is a way of organizing and managing code so that it can run in parallel. The thread is a way of keeping code running in the background while the main program is running. Threads are used to parallelize tasks and to share resources among multiple threads. When the main program runs, it sends instructions to the thread that is running the task. When the task is done, the thread that was running the task sends instructions to the main program that is waiting for instructions. This process continues until all tasks are done or until one of them crashes or gets interrupted. Threads are a fundamental concept in programming because they allow programs to run in parallel and to share resources. They are also useful for managing memory and CPU usage.
Computer Science Fundamentals Interview Questions
1. What is dynamic programming? How is it different from greedy algorithms?
Dynamic Programming (DP) is an algorithmic technique used to solve problems by breaking them into smaller overlapping subproblems and storing their results to avoid recomputation.
DP is applicable when two properties exist:
- Optimal substructure (optimal solution can be built from optimal sub-solutions)
- Overlapping subproblems
There are two common approaches:
- Top-down (memoization): Recursive solution with caching.
- Bottom-up (tabulation): Iterative solution building from smallest cases.
Classic DP problems:
- 0/1 Knapsack
- Longest Common Subsequence (LCS)
- Matrix Chain Multiplication
- Fibonacci with memoization
Greedy algorithms, in contrast, make the locally optimal choice at each step without reconsidering previous decisions. They do not store subproblem results.
Greedy works only when the greedy choice property holds, meaning a locally optimal choice leads to a globally optimal solution.
Examples:
- Fractional Knapsack -> Greedy works.
- 0/1 Knapsack -> Requires DP.
- Dijkstra’s algorithm -> Greedy (for non-negative weights).
Key differences:
| Aspect | Dynamic Programming | Greedy |
|---|---|---|
| Stores subproblems | Yes | No |
| Revisits decisions | Yes | No |
| Guarantees global optimum | Yes (if applicable) | Only when property holds |
| Complexity | Often higher | Usually lower |
DP typically has higher time and space complexity but guarantees correctness for complex optimization problems.
In interviews, common traps can be:
- Confusing recursion with DP (recursion alone is not DP).
- Not identifying overlapping subproblems.
- Applying greedy where DP is required.
2. Explain time complexity and space complexity. What is Big-O notation?
Time complexity measures how an algorithm’s running time grows as the input size increases. It does not measure actual time in seconds, it measures growth rate relative to input size nnn.
Space complexity measures how much memory an algorithm uses as input size increases. This includes:
- Input space
- Auxiliary space (extra memory used by the algorithm)
The most common way to express complexity is using Big-O notation. Big-O describes the upper bound (worst-case growth rate) of an algorithm.
For example:
- Binary Search runs in O(log n) because the search space is halved each step.
- Merge Sort runs in O(n log n) due to dividing and merging.
- Bubble Sort runs in O(n²) because of nested comparisons.
Common complexities:
| Complexity | Meaning | Example |
|---|---|---|
| O(1) | Constant time | Access array element |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Linear search |
| O(n log n) | Linearithmic | Merge sort |
| O(n²) | Quadratic | Bubble sort |
| O(2ⁿ) | Exponential | Subset generation |
Big-O is not the only notation:
- Big-Ω (Omega): Best-case lower bound.
- Big-Θ (Theta): Tight bound (exact asymptotic growth).
For example, linear search:
- Best case: O(1)
- Worst case: O(n)
- Average case: Θ(n)
Another important concept is amortized analysis. Some operations may occasionally be expensive, but over many operations, the average cost is small. For instance, dynamic arrays (like vectors) occasionally resize (O(n)), but insertion is amortized O(1) because resizing happens infrequently.
3. What is hashing? Explain hash tables and collision resolution techniques.
Hashing is a technique that maps a key to a fixed-size array index using a hash function. The goal is to achieve O(1) average time complexity for search, insert, and delete.
A hash table consists of:
- An array (buckets)
- A hash function
- A collision resolution strategy
Collisions occur when two keys produce the same hash index.
There are two major collision resolution techniques:
1. Chaining: Each bucket contains a linked list (or dynamic structure). Multiple keys can exist in the same bucket.
2. Open Addressing: All keys are stored within the array itself. If a collision occurs, probing techniques are used:
- Linear Probing
- Quadratic Probing
- Double Hashing
Important concepts:
-
Load Factor (α) = Number of elements / Table size
Higher load factor increases collisions. - Rehashing: Resizing the table when load factor exceeds a threshold.
| Technique | Storage | Advantage | Limitation |
|---|---|---|---|
| Chaining | Linked lists | Simple | Extra memory |
| Open Addressing | Array only | Cache friendly | Clustering |
Hash tables are used in:
- Dictionaries
- Caches
- Symbol tables
- Database indexing
Here are some follow-up questions that can be asked:
- What makes a good hash function?
- What is clustering?
- Why does performance degrade at high load factors?
4. What is a Binary Search Tree (BST)? What is the difference between BST, AVL tree, and B-tree?
A Binary Search Tree (BST) is a binary tree where, for every node:
- Left subtree contains values smaller than the node.
- Right subtree contains values greater than the node.
Average time complexity for search, insert, and delete is O(log n), but in the worst case (when skewed), it becomes O(n).
An AVL tree is a self-balancing BST. For every node, the height difference between left and right subtrees (balance factor) is at most 1. If imbalance occurs, rotations (LL, RR, LR, RL) are performed. AVL guarantees O(log n) time complexity even in the worst case.
A B-tree is a balanced multi-way tree optimized for disk storage. Unlike BSTs, a B-tree node can contain multiple keys and children. It minimizes disk I/O operations and is widely used in databases and file systems.
| Feature | BST | AVL | B-tree |
|---|---|---|---|
| Balancing | No | Yes | Yes |
| Worst Case | O(n) | O(log n) | O(log n) |
| Node Children | 2 | 2 | Many |
| Use Case | In-memory | In-memory balanced | Databases, file systems |
Databases prefer B+ trees (a variation of B-tree) because they are optimized for range queries and disk access.
In interviews, you can be asked questions like:
- When does a BST degrade?
- Why are rotations needed in AVL?
- Why don’t databases use simple BSTs?
5. What is a linked list? Compare singly linked list, doubly linked list, and circular linked list.
A linked list is a linear data structure where elements (nodes) are stored non-contiguously in memory. Each node contains data and one or more pointers that reference the next (and possibly previous) node.
In a singly linked list, each node contains a pointer to the next node. Traversal is one-directional. Insertion at the head is O(1), but searching is O(n).
In a doubly linked list, each node contains pointers to both the next and previous nodes. This allows bidirectional traversal and makes deletion easier if a node pointer is given.
In a circular linked list, the last node points back to the first node. This structure is useful in round-robin scheduling and cyclic processes.
| Type | Traversal | Extra Memory | Common Use |
|---|---|---|---|
| Singly | One direction | Low | Simple dynamic lists |
| Doubly | Two directions | Higher | Browser history |
| Circular | Cyclic | Depends | Scheduling systems |
Compared to arrays:
- Linked lists allow dynamic memory allocation.
- No random access (O(n) for indexing).
- Poor cache locality compared to arrays.
- Better for frequent insertions/deletions.
A common follow-up question during interviews could be why linked lists are slower than arrays despite both having O(n) traversal, the answer here will be adjacent to cache locality and contiguous memory.
6. What is the difference between stack and queue? Explain their real-world applications.
A stack is a linear data structure that follows the LIFO (Last In, First Out) principle. The last element inserted is the first one removed.
A queue is a linear data structure that follows the FIFO (First In, First Out) principle. The first element inserted is the first one removed.
Operations:
| Structure | Insert Operation | Remove Operation |
|---|---|---|
| Stack | Push | Pop |
| Queue | Enqueue | Dequeue |
A stack is heavily used in:
- Function call management (call stack)
- Undo/redo functionality
- Expression evaluation (infix to postfix)
- Backtracking algorithms (DFS)
A queue is commonly used in:
- Breadth-First Search (BFS)
- CPU scheduling
- Print spooling
- Message queues in distributed systems
Variants include:
- Circular Queue: Prevents wasted space in array implementation.
- Priority Queue: Elements are removed based on priority, not order.
- Deque (Double Ended Queue): Insertion and deletion from both ends.
Time complexity for both insertion and deletion is typically O(1).
In interviews, these topics are also covered along the lines:
- Implementation using arrays vs linked lists
- When recursion implicitly uses a stack
- Difference between stack overflow and heap overflow
7. Explain different types of joins in SQL with examples.
A JOIN in SQL is used to combine rows from two or more tables based on a related column. It is fundamental in relational databases because normalized data is often split across multiple tables.
The most commonly used join is the INNER JOIN. It returns only the rows that have matching values in both tables.
SELECT e.name, d.department_name
FROM Employees e
INNER JOIN Departments d
ON e.department_id = d.id;Only employees with a matching department_id will appear in the result.
A LEFT JOIN (LEFT OUTER JOIN) returns all rows from the left table and the matching rows from the right table. If no match exists, NULL values are returned for the right table columns.
A RIGHT JOIN is the opposite, all rows from the right table are returned, with NULLs for unmatched rows on the left.
A FULL OUTER JOIN returns all rows from both tables. If there is no match on either side, NULL values are filled in.
A CROSS JOIN returns the Cartesian product of both tables, every row of the first table combined with every row of the second table. It does not require a condition and is rarely used unless intentional.
A SELF JOIN joins a table with itself. It is commonly used in hierarchical data like employee-manager relationships.
SELECT e.name, m.name AS manager
FROM Employees e
LEFT JOIN Employees m
ON e.manager_id = m.id;Other variations include:
-
NATURAL JOIN: Automatically joins tables based on columns with the same name (not commonly recommended in production due to lack of explicitness).
-
USING clause: Simplifies join syntax when both tables share the same column name.
| Join Type | Returns |
|---|---|
| INNER JOIN | Matching rows only |
| LEFT JOIN | All left rows + matches |
| RIGHT JOIN | All right rows + matches |
| FULL OUTER JOIN | All rows from both tables |
| CROSS JOIN | Cartesian product |
From a performance perspective:
- Joins rely heavily on indexing.
- Large joins without indexes can cause full table scans.
- INNER JOIN is usually faster than OUTER JOIN because fewer rows are processed.
In interviews, candidates are often tested on:
- Difference between LEFT JOIN and INNER JOIN
- How NULLs behave in joins
- Join order and indexing impact
8. What is the difference between SQL and NoSQL databases? When to use which?
SQL databases are relational databases that store data in structured tables with predefined schemas. They follow ACID properties and are designed for strong consistency and complex queries involving joins.
Common examples include MySQL and PostgreSQL.
NoSQL databases are non-relational and designed for scalability, flexibility, and distributed architectures. They often follow the BASE model (Basically Available, Soft state, Eventually consistent).
Examples include MongoDB (document-based), Redis (key-value), Apache Cassandra (column-family), and Neo4j (graph-based).
| Aspect | SQL | NoSQL |
|---|---|---|
| Schema | Fixed | Flexible |
| Scaling | Vertical | Horizontal |
| Consistency | Strong | Often eventual |
| Best For | Transactions, complex queries | Large-scale distributed data |
SQL is preferred in financial systems and applications requiring strict consistency. NoSQL is preferred for high-throughput systems, real-time applications, and unstructured data.
9. What are the ACID properties in a database? Why are they important?
ACID is a set of properties that guarantee reliable and consistent database transactions. It ensures that even in cases of crashes, power failures, or concurrent access, the database remains correct.
Atomicity means a transaction either completes fully or does not happen at all. If any part fails, the entire transaction is rolled back.
Consistency ensures that a transaction moves the database from one valid state to another, maintaining all defined constraints and rules.
Isolation ensures that concurrent transactions do not interfere with each other. Depending on the isolation level (Read Uncommitted, Read Committed, Repeatable Read, Serializable), different types of anomalies like dirty reads or phantom reads are prevented.
Durability guarantees that once a transaction is committed, it will persist even if the system crashes. This is typically implemented using Write-Ahead Logging (WAL) and recovery logs.
| Property | Meaning | Purpose |
|---|---|---|
| Atomicity | All-or-nothing execution | Prevents partial updates |
| Consistency | Valid state transitions | Maintains integrity |
| Isolation | No interference | Prevents anomalies |
| Durability | Permanent after commit | Ensures persistence |
A common example would be: if money is debited from one account but the system crashes before crediting another, atomicity ensures the transaction is rolled back.
In interviews, candidates often confuse consistency with isolation, so clarity here is important.
10. What is virtual memory? Explain paging and segmentation.
Virtual memory is a memory management technique that allows a system to use disk storage as an extension of physical RAM. It gives each process the illusion of having a large, continuous memory space, even if physical memory is limited. This improves multiprogramming and provides process isolation.
Paging divides logical memory into fixed-size blocks called pages and physical memory into frames of the same size. A page table maps logical pages to physical frames. When a required page is not present in RAM, a page fault occurs, and the operating system loads the page from disk. Paging eliminates external fragmentation but can cause internal fragmentation due to fixed block sizes.
To improve performance, systems use a Translation Lookaside Buffer (TLB), which caches page table entries to speed up address translation.
Segmentation, in contrast, divides memory into variable-sized logical segments such as code, stack, and data. Each segment has a base address and limit. Segmentation aligns with how programmers view memory, but it can lead to external fragmentation.
| Aspect | Paging | Segmentation |
|---|---|---|
| Block Size | Fixed | Variable |
| Fragmentation | Internal | External |
| View | Physical memory-oriented | Logical memory-oriented |
Modern systems often combine paging and segmentation to balance efficiency and logical organization.
In interviews, the follow-up questions usually include TLB, thrashing, page replacement algorithms (LRU, FIFO), and differences between internal and external fragmentation.
11. Explain the different CPU scheduling algorithms. Compare preemptive vs non-preemptive.
CPU scheduling determines which process in the ready queue gets access to the CPU. The main goals are maximizing CPU utilization, minimizing waiting time, reducing turnaround time, and improving response time.
First Come First Serve (FCFS) is a non-preemptive algorithm where processes execute in order of arrival. It is simple but suffers from the convoy effect, where short jobs wait behind long ones.
Shortest Job First (SJF) selects the process with the smallest CPU burst time. It minimizes average waiting time and is theoretically optimal. However, it may cause starvation for long processes. Its preemptive version is called Shortest Remaining Time First (SRTF).
Round Robin (RR) assigns a fixed time quantum to each process. After the quantum expires, the process is moved to the end of the queue. It is widely used in time-sharing systems. If the quantum is too small, context switching overhead increases; if too large, it behaves like FCFS.
Priority Scheduling executes processes based on priority levels. It can be preemptive or non-preemptive. Starvation can occur, which is typically solved using aging (gradually increasing the priority of waiting processes).
Multi-Level Feedback Queue (MLFQ) uses multiple queues with different priority levels. Processes can move between queues based on their behavior, favoring short and interactive tasks. Modern operating systems commonly use variations of this approach.
The fundamental difference between preemptive and non-preemptive scheduling is:
| Aspect | Preemptive | Non-Preemptive |
|---|---|---|
| CPU Control | Can interrupt running process | Runs until completion or blocking |
| Responsiveness | High | Lower |
| Overhead | Higher | Lower |
Preemptive scheduling is better for interactive systems, while non-preemptive scheduling is simpler and suitable for batch systems.
In interviews, you can be asked why SJF is optimal, what starvation is, and why Round Robin is preferred in interactive environments.
12. What is the difference between process and thread? Explain with examples.
A process is an independent program in execution that has its own memory space, system resources, and execution context. The operating system isolates processes from one another, which means if one process crashes, it does not directly affect others. Each process maintains a Process Control Block (PCB), its own address space, and allocated resources like file handles and network connections.
A thread, on the other hand, is the smallest unit of execution within a process. Multiple threads can exist inside a single process, and they share the same memory space (heap and global variables). However, each thread has its own stack, program counter, and registers.
The key difference lies in memory isolation and overhead:
| Aspect | Process | Thread |
|---|---|---|
| Memory | Separate address space | Shared address space |
| Context Switching | Expensive | Faster |
| Communication | IPC mechanisms | Shared variables |
| Fault Isolation | Strong | Weak |
Because processes do not share memory, communication between them requires Inter-Process Communication (IPC) like pipes or sockets. Threads communicate directly via shared memory, which makes them faster but also prone to race conditions if synchronization is not handled properly.
There are also user-level threads (managed by libraries) and kernel-level threads (managed by the OS scheduler). Kernel-level threads allow true parallel execution on multi-core systems.
For example, in Google Chrome, each browser tab runs as a separate process for isolation, while multiple threads inside a tab handle rendering, networking, and scripting.
In interviews, the deeper expectation is that you understand the trade-off between isolation and performance, and how multithreading introduces synchronization challenges.
13. What is the difference between BFS and DFS? When to use which?
Breadth-First Search (BFS) and Depth-First Search (DFS) are graph traversal algorithms used to explore nodes and edges.
Both run in O(V + E) time when using an adjacency list representation, where:
- V = number of vertices
- E = number of edges
BFS explores the graph level by level. It uses a queue to process nodes in order of discovery.
DFS explores as deep as possible before backtracking. It uses a stack (explicitly or via recursion).
Key differences:
| Feature | BFS | DFS |
|---|---|---|
| Data Structure | Queue | Stack / Recursion |
| Traversal Pattern | Level-order | Depth-first |
| Shortest Path (Unweighted) | Yes | No |
| Memory Usage | Can be high | Usually lower |
BFS is preferred when:
- Finding shortest path in an unweighted graph
- Solving level-order traversal problems
- Checking bipartite graphs
DFS is preferred when:
- Detecting cycles
- Topological sorting
- Finding connected components
- Solving maze/backtracking problems
Graph representation also matters:
- Adjacency List: Space efficient for sparse graphs (O(V + E)).
- Adjacency Matrix: Faster edge lookup but uses O(V²) space.
Computer Science Interview Questions for Experienced
1. What is Multithreading?
Multithreading is a technique that allows multiple threads to run in parallel on a single processor. This allows multiple tasks to be run in parallel without the need for synchronization. In addition, multithreading can improve performance by allowing tasks to run in parallel without having to wait for each other to finish. For example, it is not appropriate for applications that require high performance or when the processor cannot support more than one thread at a time. Multithreading also has its own set of risks and pitfalls. For example, multithreading can lead to increased system load and increased system resource consumption.
2. What is the primary memory in programming?
The primary memory in programming is the data structure that is used to store the information that is used by the program to control the execution of the program. The primary memory is composed of variables, constants, and data types. The variables are used to store information about the current state of the program. The constants are used to store values that are known at compile-time and are needed by the program when it is run. The data types are used to store values that are known at runtime and are needed by the program when it is run.
The primary memory in programming is composed of three different types of data structures:
- Variables - These are used to store information about the current state of the program. Variables can be used to store values such as numbers, strings, and booleans.
- Constants - These are used to store values that are known at compile-time and are needed by the program when it is run. Constants can be used to store values such as integers, floating-point numbers, and booleans.
- Data types - These are used to store values that are known at runtime and are needed by the program when it is run. Data types can be used to store values such as arrays, lists, and dictionaries.
3. What is the internet?
The internet is a worldwide network of computers and devices that enables people to share information, ideas, and products. It is made up of many different types of networks, such as the internet, mobile networks, and satellite networks. The internet is used for a variety of purposes, including communication, learning, and entertainment. The internet was originally created to allow people to share information and ideas. Today, it is used for a variety of other purposes, including communication, learning, and entertainment. The internet is also an important part of the economy by connecting people around the world.
4. What is the World Wide Web?
The World Wide Web (or WWW) is a collection of interconnected data networks that enable people to share information, documents, and programs across the Internet. The web is made up of hundreds of different websites, each of which contains information about a particular topic or subject. These websites are organized into a hierarchy called a “web page” that describes the content of the page and links to other pages. Web pages can be written in many different languages, and they can be organized in many different ways, including using tabs and links. The web is a powerful tool for sharing information because it enables people to easily access information from anywhere on the planet. For example, you can access information about any topic you want from any computer or device that has Internet access. You can also use the web to share documents and programs with other people who have access to the same devices as you do.
5. What is an Algorithm?
An algorithm is a set of steps that are used to solve a problem. Algorithms are used in a variety of fields, including computer science, mathematics, and engineering. An algorithm is a set of instructions that tells a computer how to perform a task. Algorithms are used to solve problems such as sorting data, searching for patterns in data, and performing calculations. Algorithms are used in many different fields, including computer science, mathematics, and engineering. An algorithm is a set of instructions that tells a computer how to perform a task.

6. What is cryptography?
Cryptography is the science and art of creating and using codes and ciphers to protect sensitive information from unauthorized access, disclosure, or destruction. Cryptography is used to protect data from unauthorized access, modification, or disclosure. Cryptography can also be used to secure data transmissions, such as e-mail and web browsing. Cryptography also plays an important role in the security of computer networks, such as the Internet. Codes and ciphers are used to encode and decode information. For example, when you type in a password on a computer, the computer uses a code to encrypt the password. When you send an e-mail, you use a code to encrypt the message.

7. What is a singleton class?
A singleton class is a class that is defined once and only once. This can be used to reduce the number of classes you need to define in your application, and it can also be used to reduce the complexity of your code. When you define a singleton class, you are declaring that the class is only ever going to be created once. This can be useful if you want to reduce the number of instances that your class will have to create, and it can also be useful if you want to reduce the complexity of your code. Singleton classes are often used when you need to create a single instance of a class, but you don't want that instance to be shared across multiple objects. For example, if you want to create a single instance of a class that represents an image, you might create a singleton class that represents that image.
8. Is string class final?
Yes. The string class is final. This means that you cannot subclass it, and you cannot override its methods. This is a good thing because it means that you can use the string class without worrying about its internal state. There are a few things that you can do to subclass the string class, though. First, you can use StringBuilder to create a subclass of the string class. This class can then override the methods that you need to override to create your own subclass of the string class. Second, you can use StringBuffer to create a subclass of the string class. This class can then override the methods that you need to override to create your own subclass of the string class. Finally, you can use StringBuilder and StringBuffer together to create a subclass of the string class.
9. What is a wrapper class?
A wrapper class is a class that inherits from another class and then provides a set of methods and/or properties that are specific to its own purpose. Wrappers are typically used to hide implementation details from the user, allowing the developer to concentrate on the business logic. A wrapper class can be used to hide implementation details from the user, allowing the developer to concentrate on the business logic. Wrappers can also be used to provide a set of methods and/or properties that are specific to their own purpose. The main advantage of wrappers is that they allow you to hide implementation details from the user, allowing you to concentrate on the business logic. The main disadvantage of wrappers is that they can be difficult to maintain.
10. What are multiple inheritances in Java?
Multiple inheritances are a way of passing on multiple copies of a particular class or interface to a child's class. This can be useful when you want to make sure that some code is always available to your child's classes. One way to do this is to create a subclass of the parent class, and then provide the child with a copy of the parent class. Another way is to create multiple inheritances in your Java code, and then provide the child with a reference to the parent class. Multiple inheritances are useful for situations where you need to make sure that some code is always available to your child's classes. In Java, multiple inheritances are implemented using the public and private modifiers on a class or interface. When multiple inheritances are present, the public modifier indicates that the class or interface is publically accessible. The private modifier indicates that the class or interface is privately accessible. Multiple inheritances can be useful when you want to make sure that some code is always available to your child's classes.

11. What is Cache?
A cache is a temporary storage location for frequently accessed data. Caches are useful for organizations that need to store large amounts of data in a short amount of time. They can also be used to improve performance by reducing the amount of data that needs to be retrieved from the network. Caches can be used to store data in several different ways. They can be used to store data that is frequently accessed, such as documents or images. They can also be used to store data that is rarely accessed, such as log files or application states. They can also be used to store data that is needed only occasionally, such as temporary files or cookies.

12. What is Deadlock?
A deadlock is a situation where two or more processes are waiting for each other to finish. Deadlock occurs when one process is waiting for another process to finish before it can continue. The process that is waiting will not finish until the other process finishes. This can be a problem if you need to wait for a long time, as this can lead to your system becoming unresponsive.

13. What is a Critical Section?
A critical section is a section of code that is crucial to the operation of a program. By accessing critical sections, a program can make changes to the overall functionality of the program without affecting other sections of code. Critical sections are often accessed through functions, methods, and variables. The purpose of a critical section is to ensure that all parts of the program are working properly.

14. What is normalization in a Database?
Normalization is a process of abstracting and simplifying data. It is a way of making data easier to understand and easier to work with. For example, if you have a data set that contains a lot of numbers, you can normalize it by taking the numbers and breaking them down into smaller pieces, such as by dividing by 10. This makes it easier to work with the data and makes it easier to see trends and patterns. You can also normalize your data by making it more consistent.
15. What is Indexing in DBMS?
Indexing is the process of organizing data in a way that makes it easier to find and access. In a database, the index is a collection of data organized in a way that makes it easy to search and find data. The index consists of a set of key-value pairs that can be used to reference data in the database. The indexing process can involve many different techniques, including the use of indexes, data structures, and algorithms. In a database, the index is a collection of data organized in a way that makes it easy to search and find data.
16. Explain firewalls?
Firewalls are software programs that are used to protect your computer from viruses and other malware. They are also used to protect your privacy and to keep unauthorized people from accessing your computer. Firewalls are often used in conjunction with antivirus software. They can help to block malicious programs from entering your computer, while also protecting you from unknown programs. In order to use a firewall, you will need to install it on your computer. It is important that you do this correctly since it can prevent your computer from being infected with malware. Firewalls can also be used in conjunction with antivirus software. They can help to block malicious programs from entering your computer, while also protecting you from unknown programs.
17. What is TCP?
TCP stands for Transmission Control Protocol. TCP is a networking protocol that is used to transfer data between computers. TCP is a connection-oriented protocol that allows two computers to establish a connection with each other. TCP also allows two computers to send and receive data. The main purpose of TCP is to keep the data transferred between two computers connected. This is done by ensuring that data packets are sent and received in a timely manner. TCP also provides several other functions, such as error detection and recovery, congestion control, and reliability.

18. Explain DNS?
DNS is the acronym for Domain Name System. It's a way of mapping domain names to IP addresses. The IP address is a number that's assigned to each device that connects to the Internet. When you type in a domain name, your computer sends a request to the DNS server, which looks up the corresponding IP address. The DNS server then returns a response that includes the domain name and an associated IP address. This process is called name resolution. DNS is used by most websites and services that use the Internet. It's also used by email services like Gmail and Yahoo Mail, as well as by many online services like shopping sites and online banking services.

19. What are the Application layer protocols?
The Application layer protocols are the protocols that are used to connect applications to the network. These protocols are responsible for transferring data between applications and the network, such as TCP/IP, HTTP, and FTP. The Application layer protocols are also responsible for handling security and privacy. For example, the HTTP protocol is used to transfer data between web pages and the network. The HTTP protocol is also used to protect privacy by encrypting data before it is sent over the network.

20. What are the keys in DBMS?
There are four main keys to a database management system (DBMS): data, integrity, availability, and management. Data is the information stored in the database. Integrity is the ability of the database to prevent the corruption of data. Availability is the ability of the database to provide access to data when needed. Management is the ability of the database to provide tools for administrators and users. In addition, there are many other factors that are important in choosing a DBMS, such as a price, performance, and ease of use.

Conclusion
These articles provide a summary of some of the most common interview questions that you may encounter in your career search. The first thing you should do is to prepare for the interview. This will help you to understand the type of questions that you are likely to be asked. You should also practice answering the questions that you are likely to be asked so that you are able to prepare yourself for the interview. Finally, it is important to remember that the interview is only one part of the process and that there are many other factors that will influence your decision to hire or not hire.
Useful Resources
Technical Interview Questions Computer Science
1. How does the internet work end-to-end when you type a URL in a browser?
When you type a URL into a browser and press Enter, multiple systems coordinate to fetch and display the webpage. The process happens in layers.
First, the browser checks:
- Browser cache
- OS cache
- Router cache
If the IP address is not cached, a DNS lookup begins. The browser queries a recursive DNS resolver, which may perform iterative queries to:
- Root DNS servers
- Top-level domain (TLD) servers
- Authoritative DNS servers
Once the IP address is resolved, the browser establishes a connection to the server.
If the site uses HTTP:
- A TCP 3-way handshake occurs (SYN -> SYN-ACK -> ACK).
If the site uses HTTPS:
- TCP handshake first
- Then a TLS handshake to establish encryption
After the secure connection is established:
- The browser sends an HTTP request (GET /index.html)
- The request may pass through load balancers and CDNs
- The server processes the request (possibly querying databases or services)
The server sends back an HTTP response:
- Status codes like 200 (OK), 301 (Redirect), 404 (Not Found), 500 (Server Error)
The browser then:
- Parses HTML -> builds DOM
- Parses CSS -> builds CSSOM
- Combines into render tree
- Performs layout and paint
Modern systems may involve:
- CDN caching for static assets
- Load balancers distributing traffic
- Reverse proxies
- Microservices internally
This question tests whether you understand networking, DNS, TCP, TLS, HTTP, and browser rendering as one connected system.
2. What is the difference between HTTP and HTTPS? How does TLS/SSL work?
HTTP (HyperText Transfer Protocol) is a stateless application-layer protocol used for transferring data between client and server. It runs on port 80 and sends data in plaintext.
HTTPS is HTTP over TLS (Transport Layer Security). It runs on port 443 and encrypts communication between client and server.
The key difference is encryption and authentication.
TLS works using asymmetric and symmetric cryptography.
During the TLS handshake:
- Client sends "Client Hello" (supported cipher suites).
- Server replies with "Server Hello" and its digital certificate.
- The certificate is verified by a Certificate Authority (CA).
- Client and server agree on a session key.
- Symmetric encryption begins for the session.
Public-key cryptography is used only during key exchange because it is computationally expensive. After that, symmetric encryption is used for performance.
| Aspect | HTTP | HTTPS |
|---|---|---|
| Encryption | No | Yes (TLS) |
| Port | 80 | 443 |
| Security | Vulnerable to MITM | Encrypted & authenticated |
HTTPS is mandatory for:
- Login systems
- Payment gateways
- Authentication tokens
- Sensitive APIs
Modern improvements:
- HTTP/2 -> multiplexing, header compression
- HTTP/3 -> uses QUIC (built over UDP) for reduced latency
3. What is the difference between TCP and UDP? When would you choose one over the other?
TCP and UDP are transport-layer protocols used for data transmission.
TCP (Transmission Control Protocol) is connection-oriented and reliable. Before sending data, it establishes a connection using a 3-way handshake. It guarantees:
- Ordered delivery
- Error checking
- Retransmission of lost packets
- Flow control
- Congestion control
UDP (User Datagram Protocol) is connectionless and does not guarantee delivery, order, or duplication protection.
| Feature | TCP | UDP |
|---|---|---|
| Connection | Yes | No |
| Reliability | Guaranteed | No guarantee |
| Ordering | Maintained | Not maintained |
| Speed | Slower | Faster |
| Overhead | High | Low |
TCP is used for:
- HTTP/HTTPS
- FTP
- Email protocols
UDP is used for:
- DNS queries
- Online gaming
- Video streaming
- VoIP
DNS uses UDP because:
- Queries are small
- Speed matters more than reliability
- Retries can happen at application level
4. Explain the concept of API. What is the difference between REST and SOAP?
An API (Application Programming Interface) is a defined way for software components to communicate with each other. It specifies how requests are made and responses are structured.
In web systems, APIs typically use HTTP.
REST (Representational State Transfer) is an architectural style for building APIs. It is:
- Stateless
- Resource-based
- Uses standard HTTP methods (GET, POST, PUT, DELETE)
- Typically returns JSON
SOAP (Simple Object Access Protocol) is a protocol that:
- Uses XML-based message envelopes
- Follows strict standards
- Supports WS-Security
- Uses WSDL for contract definition
| Aspect | REST | SOAP |
|---|---|---|
| Type | Architectural style | Protocol |
| Format | JSON (commonly) | XML |
| State | Stateless | Can be stateful |
| Flexibility | High | Strict |
REST is widely used for:
- Web applications
- Mobile backends
- Public APIs
SOAP is still used in:
- Enterprise systems
- Banking systems
- Environments requiring strict contracts and security compliance
Interview follow-ups include:
- What makes an API idempotent?
- What are HTTP status codes?
- What is rate limiting?
5. What is the difference between compiler and interpreter? Give examples.
A compiler translates the entire source code into machine code before execution. The generated executable runs directly on hardware.
An interpreter executes code line by line at runtime without generating a separate executable.
Examples:
- Compiled languages: C, C++, Go
- Interpreted languages: Python, Ruby (historically JavaScript)
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Entire program first | Line-by-line |
| Speed | Faster execution | Slower execution |
| Error Detection | Before execution | During execution |
| Output | Executable file | No separate file |
Modern systems often use hybrid models.
Java compiles source code into bytecode, which runs on the JVM (Java Virtual Machine). The JVM uses JIT (Just-In-Time) compilation to convert bytecode into machine code at runtime.
Similarly, .NET uses CLR with JIT compilation.
Transpilers convert one high-level language to another, such as TypeScript to JavaScript.
Trade-offs:
- Compilers -> better runtime performance
- Interpreters -> better portability and debugging flexibility
6. What is recursion? Explain with examples and discuss its limitations.
Recursion is a programming technique where a function calls itself to solve a smaller version of the same problem. Every recursive solution must have:
- A base case - the stopping condition
- A recursive case - where the function calls itself with a smaller input
For example, factorial:fact(n) = n * fact(n-1)
fact(0) = 1
Each recursive call is placed on the call stack. The stack stores:
- Function parameters
- Local variables
- Return address
When the base case is reached, the stack starts unwinding.
Common recursive use cases:
- Tree traversal (DFS)
- Merge sort and quicksort
- Fibonacci sequence
- Backtracking problems
However, recursion has limitations.
First, deep recursion can cause stack overflow because each function call consumes stack memory. Languages have recursion depth limits (for example, Python’s default recursion limit).
Second, recursion can be inefficient if the problem contains overlapping subproblems. A classic example is naive Fibonacci, which runs in O(2ⁿ) time. This can be improved using memoization, which stores previously computed results.
Third, recursion may be slower than iteration due to function call overhead.
Some languages support tail recursion optimization (TCO), where the compiler converts certain recursive calls into iterative loops, reducing stack usage. However, not all languages guarantee TCO.
In interviews, recursion is often preferred for clarity (especially in tree and graph problems), but iteration may be better when:
- Stack depth is large
- Performance is critical
- The logic is straightforward
The key is knowing when recursion simplifies thinking, and when it becomes a liability.
7. What are design patterns? Explain Singleton, Factory, and Observer with use cases.
Design patterns are reusable solutions to common software design problems. They are not code snippets, but proven architectural templates.
They are generally categorized into:
- Creational patterns
- Structural patterns
- Behavioral patterns
1. Singleton (Creational Pattern): Ensures that a class has only one instance and provides a global access point to it.
For example:
- Logger
- Database connection pool
- Configuration manager
However, Singleton can introduce hidden global state and tight coupling. It makes unit testing difficult because dependencies become implicit. In modern systems, dependency injection is often preferred over Singleton.
2. Factory (Creational Pattern): Encapsulates object creation logic and delegates it to subclasses or dedicated factory classes.
Instead of directly calling a constructor, the client requests an object from a factory.
For example:
- Payment gateway selection (CreditCard, UPI, PayPal)
- UI component rendering
- Database driver selection
Factory improves flexibility and reduces tight coupling to concrete implementations.
3. Observer (Behavioral Pattern): Defines a one-to-many dependency between objects. When one object changes state, all observers are notified automatically.
For example:
- Event listeners in UI frameworks
- Publish-subscribe systems
- Real-time notification systems
| Pattern | Category | Use Case |
|---|---|---|
| Singleton | Creational | One shared instance |
| Factory | Creational | Object creation control |
| Observer | Behavioral | Event-driven updates |
In interviews, candidates are often asked:
- When not to use Singleton
- Difference between Factory and Abstract Factory
- How Observer differs from Pub-Sub
8. What is version control? Explain Git branching strategies.
Version control is a system that tracks changes to source code over time. It enables collaboration, history tracking, rollback, and parallel development.
Git is a distributed version control system, meaning every developer has a full copy of the repository, including history.
Branching is a core Git feature. It allows teams to work on features independently without affecting the main codebase.
Common branching strategies:
Git Flow
- main (production)
- develop (integration branch)
- feature branches
- release branches
- hotfix branches
Best for structured releases and larger teams, but can be heavy.
GitHub Flow
- main branch
- Short-lived feature branches
- Pull Request (PR)-based workflow
Simple and effective for continuous deployment environments.
Trunk-Based Development
- Single main branch (trunk)
- Very short-lived branches
- Frequent merges
Encourages small, incremental changes and reduces merge conflicts.
Merge vs Rebase:
- Merge creates a new merge commit.
- Rebase rewrites commit history for a cleaner timeline.
Conflict resolution is a natural part of branching and requires understanding how changes overlap.
Branching strategy impacts:
- Team velocity
- Release frequency
- Deployment complexity
9. What is the difference between monolithic and microservices architecture?
A monolithic architecture is a single, unified application where all components (UI, business logic, database access) are part of one deployable unit.
A microservices architecture breaks an application into independent services that communicate over APIs.
Monolith characteristics:
- Single codebase
- Single deployment unit
- Easier initial development
- Simpler testing and debugging
Microservices characteristics:
- Independently deployable services
- Technology flexibility
- Horizontal scalability
- Decentralized data management
| Feature | Monolith | Microservices |
|---|---|---|
| Deployment | Single unit | Multiple services |
| Scaling | Entire app | Individual services |
| Complexity | Lower initially | Higher operational complexity |
| Team Structure | Small teams | Multiple autonomous teams |
Microservices introduce challenges like:
- Network latency
- Distributed transactions
- Data consistency
- Observability and monitoring
Inter-service communication may use:
- REST
- gRPC
- Message queues (Kafka, RabbitMQ)
Monolith is often the better choice for:
- Startups
- Small teams
- Early-stage products
Microservices can be opted when:
- System complexity grows
- Independent scaling is needed
- Teams are large and autonomous
10. What is CI/CD? Explain the pipeline stages.
CI/CD stands for Continuous Integration and Continuous Delivery (or Continuous Deployment).
Continuous Integration (CI) means that every code change is automatically built and tested. Developers integrate code frequently into a shared repository.
Continuous Delivery ensures that code is always in a deployable state and can be released to production at any time.
Continuous Deployment goes one step further, every successful build is automatically deployed to production.
A typical CI/CD pipeline:
- Code commit
- Build stage
- Unit tests
- Integration tests
- Artifact creation
- Deployment to staging
- Acceptance testing
- Production deployment
Common tools:
- Jenkins
- GitHub Actions
- GitLab CI
Key concepts:
- Artifact management
- Automated testing
- Rollback strategies
- Blue-green deployment
- Canary releases
CI/CD improves:
- Deployment frequency
- Code quality
- Faster feedback cycles
- Reduced manual errors
11. What is the CAP theorem? Explain with real-world database examples.
The CAP theorem states that in a distributed system, you can guarantee only two out of the following three properties simultaneously:
- Consistency (C) - Every read receives the most recent write (all nodes see the same data at the same time).
- Availability (A) - Every request receives a response, even if it’s not the most recent data.
- Partition Tolerance (P) - The system continues operating despite network partitions (communication failures between nodes).
In a distributed system, multiple nodes communicate over a network to replicate and synchronize data.If a network failure occurs (a partition), some nodes cannot exchange updates. At that point, the system must choose: either reject requests to keep data consistent (Consistency) or continue serving requests with possibly stale data (Availability).
There are three possible combinations:
1. CP (Consistency + Partition Tolerance): The system prioritizes consistency over availability. If a partition occurs, some requests may be rejected to maintain correctness.
Example: MongoDB (in certain configurations). During a network partition, it may refuse writes to maintain consistency.
2. AP (Availability + Partition Tolerance): The system prioritizes availability. It continues serving requests even if some nodes are out of sync.
Example: Apache Cassandra. It allows writes during partitions and resolves inconsistencies later.
This leads to eventual consistency, where data may be temporarily inconsistent but converges over time.
3. CA (Consistency + Availability): Possible only when there is no partition. Traditional single-node relational databases behave like CA systems because there is no distributed network to fail.
| System Type | Guarantees |
|---|---|
| Single-node RDBMS | CA |
| MongoDB (config-dependent) | CP |
| Cassandra | AP |
An important extension is the PACELC theorem:
- If there is a Partition (P), choose between Availability (A) and Consistency (C).
- Else (E), choose between Latency (L) and Consistency (C).
This explains why some systems choose lower latency even when there is no failure.
12. How would you design a URL shortener? Walk through the system design.
Here is a step-by-step explanation on how you can design a URL shortener:Client → API Layer → Application Server → Database
↓
Cache
The system consists of:
- API servers (handle requests)
- Database (store mappings)
- Cache (speed up reads)
Step 3: Generating Short URLs
We need a unique key.
Common approaches:
Base62 Encoding
- Convert an auto-increment ID into base62 (a-z, A-Z, 0-9).
- Produces short, readable URLs.
- Deterministic and collision-free if ID is unique.
Hashing (MD5/SHA) + Truncation
- Hash original URL
- Take first few characters
- Must handle collisions carefully
Base62 with unique ID is simpler and more predictable.
Step 4: Database Choice
SQL:
- Strong consistency
- Simple schema (id, original_url, created_at)
NoSQL:
- Better horizontal scaling
- Easier sharding
For very high scale, NoSQL systems like Apache Cassandra may be preferred.
Step 5: Read Optimization
URL shorteners are read-heavy systems.
Use caching layer:
- Redis or Memcached
- Store frequently accessed mappings
- Reduce database load
Step 6: Redirection Type
Use HTTP status codes:
- 301 (Permanent Redirect) -> cached by browsers
- 302 (Temporary Redirect) -> not permanently cached
If analytics tracking is important, 302 may be preferable.
Step 7: Scaling Strategy
To scale:
- Horizontal scaling of API servers behind load balancer
- Database sharding (by key range or hash)
- Read replicas
- Rate limiting to prevent abuse
- TTL support for expiring links
Step 8: Handling Collisions
If using hashing:
- Check for existing key
- Regenerate if collision occurs
If using incremental ID:
- Collision risk is minimal if ID is unique
Step 9: Additional Considerations
- Custom aliases
- Analytics storage
- Spam detection
- CDN for global latency reduction
- Monitoring and observability
Step 1: Requirements
Functional requirements:
- Shorten a long URL
- Redirect short URL to original
- Track analytics (click count, timestamp)
Non-functional requirements:
- High availability
- Low latency (redirection must be fast)
- Scalable to millions of URLs
- Handle high read traffic
Step 2: High-Level Architecture
Typical flow:
Frequently Asked Questions
1. How can you add value to the company?
I recently completed a team project at my previous job, and I devised strategies for improving teamwork and communication among team members. Back in my previous job, I designed strategies for improving teamwork and communication among team members. I can provide your organisation with both my previous experiences and my desire for innovation.
2. Describe a project you have worked on?
I have worked on several projects over the years, but I have to say that my favourite one was the one I did for the IIT Bombay. It was a project that involved a lot of data analysis and data visualization. I was responsible for creating a dashboard that showed the students’ performance in their classes. The dashboard was designed to help the students understand how they were doing and what they needed to do to improve their grades. It was an interesting project because it involved a lot of data analysis and visualization. The project was a huge success, and it helped me learn a lot about data analysis and visualization.
3. Why did you choose computer science?
Computer science is a very broad field that encompasses a wide range of topics, including computer programming, data analysis, and computer hardware and software design. There are many reasons that someone might choose to study computer science, including the desire to learn a new skill or the hope of finding a job in a field that requires technical knowledge. However, there are also some general benefits to choosing this field. For one, computer science is an excellent way to develop problem-solving skills. This can be useful when you’re faced with a tough problem or when you’re looking for a new job. Additionally, computer science can help you to develop your critical thinking and problem-solving skills. This can be useful if you’re faced with a difficult situation or if you’re looking for a new job. Computer science also has the potential to give you access to a wide range of opportunities, including internships and scholarships. However, it’s important to remember that there are many different types of computer science, so it’s important to choose the right one for you.
4. What is your biggest achievement?
My greatest professional accomplishment was completing my Bachelor's degree in four years with a 3.9 GPA. My family's financial situation did not impact my Economics degree. As a result, I prioritized my time and built good habits to achieve it. I believe this experience will give me an advantage in my profession.
5. Why are you interested in this job (related to CS)?
My primary objective is to land a job with a long-term career opportunity where I can also learn Python using. Python is one of the duties listed in the job description, so I am certain that it will play a significant role. It also promises to be a highly skilled and cooperative department, which would help my career advancement. The company's reputation for supporting the development of its workforce may also play a role. It seems like a good match after all.
Computer Science MCQ
A dynamic array can overcome the limitation of a static array.
How many flip-flops are there in an 8085 microprocessor flag register?
How many opcodes are present in an 8-bit microprocessor.
The dynamic programming problems can be solved using a greedy algorithm.
What is system software?
What S value is generated if the Add R1, R2, R3 instruction is executed in a pipelined system?
Which data link layer task is not performed by this layer?
Which of the following describes CPU scheduling algorithms in Operating Systems?
Which phase of the compiler is the lexical Analyser used in?
Which relations contain information about a single entity?