100 Computer Science Interview Questions with Analytical Answers
Here is a set of 100 Computer Science Interview Questions with Analytical Answers set designed for freshers, students, software developers, and technical interviews. The answers focus on why, how, trade-offs, and practical reasoning, rather than simple definitions.
Table of Contents
Fundamentals
1. What is Computer Science?
Answer:
Computer Science is the study of computation, algorithms, data, software, hardware, and the systems that process information. Analytically, it is not limited to programming. Programming is a tool used to implement computational solutions.
For example, when designing a search engine, computer science involves:
- Choosing efficient algorithms.
- Designing appropriate data structures.
- Managing memory and storage.
- Handling concurrent users.
- Designing scalable networks and databases.
Thus, Computer Science combines theory, algorithms, systems, and practical implementation.
2. What is an Algorithm?
Answer:
An algorithm is a finite sequence of well-defined steps used to solve a problem.
An algorithm should ideally be:
- Correct.
- Finite.
- Unambiguous.
- Efficient.
For example, to find an element in a sorted array, binary search repeatedly divides the search space into two parts. Its time complexity is O(log n), whereas linear search requires O(n) in the worst case.
The important interview consideration is not merely whether an algorithm works, but how efficiently it works as input size increases.
3. What is a Data Structure?
Answer:
A data structure is a method of organizing and storing data so that operations can be performed efficiently.
Examples include:
- Array
- Linked List
- Stack
- Queue
- Hash Table
- Tree
- Graph
The appropriate data structure depends on the operations required. For example, a hash table is useful when fast average-case key-based lookup is important, while a tree may be preferable when ordered data and range operations are needed.
4. What is Time Complexity?
Answer:
Time complexity describes how an algorithm’s running time grows as the input size increases.
For example:
- Linear search → O(n)
- Binary search → O(log n)
- Nested loop over n elements → often O(n²)
Suppose an algorithm processes 1 million records. An O(n²) algorithm may perform approximately 1 trillion basic operations in a simplified model, while O(n log n) is dramatically smaller.
Therefore, time complexity helps determine whether an algorithm can scale.
5. What is Space Complexity?
Answer:
Space complexity measures how much additional memory an algorithm requires as input size grows.
For example, an algorithm that creates an additional array of size n has O(n) auxiliary space.
An algorithm that modifies the input array directly may use O(1) auxiliary space.
When optimizing software, time and space often involve a trade-off: using additional memory can sometimes significantly reduce execution time.
6. What is Big-O Notation?
Answer:
Big-O notation describes an algorithm’s asymptotic upper growth rate.
For example:
O(1) Constant
O(log n) Logarithmic
O(n) Linear
O(n log n) Linearithmic
O(n²) Quadratic
O(2ⁿ) Exponential
If an algorithm has O(n²) complexity, doubling n can approximately quadruple the dominant work.
Big-O therefore helps compare algorithms independently of specific hardware or programming language.
7. What is the difference between an array and a linked list?
Answer:
| Feature | Array | Linked List |
| Memory | Usually contiguous | Non-contiguous nodes |
| Random access | O(1) | O(n) |
| Insertion at beginning | O(n) | O(1) if pointer available |
| Memory overhead | Low | Higher due to pointers |
| Cache locality | Usually better | Usually poorer |
An array is generally preferable when frequent indexing is required. A linked list becomes useful when frequent insertions/deletions are needed at known positions.
8. What is a Stack?
Answer:
A stack follows LIFO — Last In, First Out.
Example:
Push A
Push B
Push C
Pop → C
Stacks are used in:
- Function calls.
- Recursion.
- Expression evaluation.
- Undo operations.
- Depth-first search.
The analytical importance is that stack operations such as push and pop are generally O(1).
9. What is a Queue?
Answer:
A queue follows FIFO — First In, First Out.
Example:
A → B → C
If A enters first, A is normally processed first.
Queues are useful for:
- CPU scheduling.
- Printer queues.
- Network requests.
- Breadth-first search.
- Message processing.
Queues are particularly useful when tasks must be processed according to arrival order.
10. What is a Hash Table?
Answer:
A hash table stores key-value pairs using a hash function.
Example:
“John” → 101
“Mary” → 102
A good hash function distributes keys across buckets.
Average-case operations can be approximately O(1), although collisions can cause performance degradation.
Hash tables are therefore excellent for fast lookup but generally do not provide naturally sorted ordering.
Object-Oriented Programming
11. What is Object-Oriented Programming?
Answer:
Object-Oriented Programming, or OOP, organizes software around objects containing data and behavior.
Its major principles are:
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
The main advantage is managing complexity by dividing a large system into smaller, interacting components.
12. What is Encapsulation?
Answer:
Encapsulation means combining data and the operations that manipulate it while controlling direct access to internal state.
For example:
BankAccount
balance
deposit()
withdraw()
Instead of allowing arbitrary modification of balance, the class can enforce rules through methods.
This protects data integrity and reduces unintended dependencies.
13. What is Abstraction?
Answer:
Abstraction hides unnecessary implementation details and exposes only the functionality required by the user.
For example, when using:
sort(array)
the programmer does not need to know every internal operation used by the sorting implementation.
Abstraction reduces cognitive complexity and allows implementations to change without necessarily affecting users.
14. What is Inheritance?
Answer:
Inheritance allows one class to derive properties and behaviors from another class.
For example:
Vehicle
↓
Car
A Car may inherit general vehicle behavior.
However, excessive inheritance can create tightly coupled class hierarchies. In modern software design, composition is often preferred when inheritance does not represent a genuine “is-a” relationship.
15. What is Polymorphism?
Answer:
Polymorphism means that the same interface can represent different implementations.
For example:
Shape.draw()
could behave differently for:
Circle
Rectangle
Triangle
This allows code to depend on an abstraction rather than a specific implementation.
16. What is Method Overloading?
Answer:
Method overloading means defining multiple methods with the same name but different parameter lists.
Example:
calculate(int a, int b)
calculate(double a, double b)
The compiler determines which version to invoke based on the arguments.
It is generally associated with compile-time polymorphism.
17. What is Method Overriding?
Answer:
Method overriding occurs when a subclass provides its own implementation of a method inherited from a parent class.
Example:
Animal → sound()
Dog → sound()
Cat → sound()
The actual implementation may depend on the runtime object.
This supports runtime polymorphism and flexible object-oriented designs.
18. Interface vs Abstract Class?
Answer:
| Interface | Abstract Class |
| Defines a contract | Defines a partial implementation |
| Useful for common capability | Useful for related classes |
| Usually less implementation state | Can contain state |
| Supports loose coupling | Can share common implementation |
Use an interface when different classes should follow the same contract, even if they are otherwise unrelated.
19. What is Constructor?
Answer:
A constructor initializes an object when it is created.
For example:
Student(“Rahul”, 20)
may initialize:
name = Rahul
age = 20
Constructors are important because they establish the initial valid state of an object.
20. What is a Destructor?
Answer:
A destructor is responsible for cleanup when an object is destroyed in languages that support deterministic destruction mechanisms.
It may release resources such as:
- Memory.
- File handles.
- Network connections.
- Locks.
In garbage-collected languages, memory cleanup is generally handled automatically, although external resources may still require explicit management.
Operating Systems
21. What is an Operating System?
Answer:
An Operating System acts as an intermediary between applications and hardware.
Its responsibilities include:
- Process management.
- Memory management.
- File management.
- Device management.
- Security.
- Resource allocation.
Without an OS, applications would need to directly manage many hardware details.
22. What is a Process?
Answer:
A process is a program in execution.
A process typically has:
- Program code.
- Memory space.
- Registers.
- Stack.
- Heap.
- Process state.
For example, opening a browser may create one or more processes depending on the browser architecture.
23. What is a Thread?
Answer:
A thread is a unit of execution within a process.
Multiple threads can share:
- Memory.
- Heap.
- Resources.
But each thread generally has its own:
- Stack.
- Registers.
- Execution state.
Threads can improve responsiveness and concurrency but introduce synchronization challenges.
24. Process vs Thread?
Answer:
| Process | Thread |
| Independent execution environment | Exists inside a process |
| Separate address space | Usually shares process memory |
| More expensive to create | Usually cheaper |
| Stronger isolation | Less isolation |
| Communication is more expensive | Communication is easier but requires synchronization |
Processes provide stronger isolation, while threads can provide efficient concurrency.
25. What is Multithreading?
Answer:
Multithreading allows multiple threads to execute concurrently within a process.
For example, a web application may have separate tasks for:
- Processing requests.
- Reading data.
- Performing calculations.
Multithreading can improve throughput, but shared data introduces problems such as race conditions and deadlocks.
26. What is a Race Condition?
Answer:
A race condition occurs when the result depends on the unpredictable timing of concurrent operations.
Suppose two threads execute:
balance = balance + 100
balance = balance – 50
If both read the old balance before either writes the result, one update may be lost.
Synchronization mechanisms such as locks, atomic operations, or carefully designed concurrent structures can prevent this.
27. What is a Deadlock?
Answer:
Deadlock occurs when processes or threads wait indefinitely for resources held by one another.
A classic example:
Thread A holds Lock 1 → waits for Lock 2
Thread B holds Lock 2 → waits for Lock 1
Neither can proceed.
Deadlocks can be reduced through consistent lock ordering, avoiding unnecessary locks, and timeout-based strategies.
28. What is Virtual Memory?
Answer:
Virtual memory allows programs to use an address space that is larger or more flexible than the immediately available physical RAM.
The OS can move memory pages between RAM and secondary storage.
The advantage is greater flexibility and isolation, but excessive paging can cause thrashing, significantly reducing performance.
29. What is Paging?
Answer:
Paging divides virtual memory into fixed-size pages and physical memory into frames.
A virtual address is translated into a physical address using page tables.
Paging helps:
- Manage memory efficiently.
- Provide process isolation.
- Support virtual memory.
However, address translation introduces overhead, which is reduced through mechanisms such as the TLB.
30. What is Context Switching?
Answer:
Context switching occurs when the CPU switches from one process or thread to another.
The system must preserve the current execution state and load another state.
Context switching enables multitasking but has overhead. Excessive context switching can reduce overall system efficiency.
Databases
31. What is a Database?
Answer:
A database is an organized system for storing and retrieving structured or semi-structured information.
A database management system provides:
- Data storage.
- Query processing.
- Transactions.
- Security.
- Concurrency control.
- Recovery.
The goal is not simply storing data but providing reliable and efficient access to it.
32. What is DBMS?
Answer:
A Database Management System is software used to create, manage, query, and secure databases.
Examples include:
- MySQL
- PostgreSQL
- Oracle Database
- SQL Server
A DBMS abstracts storage details and provides controlled access to data.
33. What is a Relational Database?
Answer:
A relational database organizes data into tables consisting of rows and columns.
For example:
Students
ID | Name | Course
1 | A | CS
2 | B | IT
Relationships between tables are represented using keys.
Relational databases are particularly useful when data has strong structure and relationships.
34. What is SQL?
Answer:
SQL stands for Structured Query Language.
It is used to:
- Retrieve data.
- Insert records.
- Update records.
- Delete records.
- Define database structures.
Example:
SELECT name
FROM students
WHERE marks > 80;
SQL allows declarative specification of what data is required rather than manually describing every retrieval step.
35. What is a Primary Key?
Answer:
A primary key uniquely identifies each row in a table.
For example:
Student_ID
101
102
103
A primary key prevents duplicate identity values and allows other tables to reference the record reliably.
36. What is a Foreign Key?
Answer:
A foreign key references a key in another table.
Example:
Students
Student_ID
Orders
Student_ID
The foreign key establishes a relationship between the two tables.
This helps maintain referential integrity.
37. What is Database Normalization?
Answer:
Normalization organizes data to reduce unnecessary duplication and update anomalies.
For example, storing customer information repeatedly in every order can create redundancy.
Normalization separates the data into related tables.
However, extreme normalization may increase the number of joins. Therefore, practical database design sometimes uses controlled denormalization for performance.
38. What is an Index?
Answer:
An index is an additional data structure that accelerates data retrieval.
For example, indexing:
can make searches for a particular email much faster.
The trade-off is that indexes:
- Consume storage.
- Increase write/update cost.
Therefore, indexing every column is usually not a good strategy.
39. What is a Transaction?
Answer:
A transaction is a logical unit of database work.
For example, transferring money requires:
Debit Account A
Credit Account B
Both operations should be treated as one logical operation.
If one succeeds and the other fails, the database should preserve consistency.
40. What are ACID Properties?
Answer:
Atomicity: All operations succeed or the transaction is rolled back.
Consistency: Database rules remain valid.
Isolation: Concurrent transactions should not improperly interfere.
Durability: Committed changes survive system failures.
ACID properties are important when correctness is more important than simply maximizing throughput.
Computer Networks
41. What is a Computer Network?
Answer:
A computer network connects devices so they can exchange data and share resources.
Networks involve:
- Protocols.
- Addresses.
- Routing.
- Switching.
- Security.
- Transmission media.
The Internet is a large collection of interconnected networks using standardized protocols.
42. What is an IP Address?
Answer:
An IP address identifies a device or network interface within an IP network.
IPv4 uses 32-bit addresses, while IPv6 uses 128-bit addresses.
For example:
192.168.1.10
is a typical IPv4 private address.
IP addresses enable packets to be routed between network destinations.
43. What is DNS?
Answer:
DNS, or Domain Name System, translates human-readable domain names into network addresses.
For example:
example.com
↓
IP address
Without DNS, users would need to remember numerical IP addresses.
DNS is therefore essentially a distributed naming system for the Internet.
44. What is HTTP?
Answer:
HTTP is an application-layer protocol used for communication between clients and servers.
A typical request contains:
Method
URL
Headers
Optional Body
Common methods include:
GET
POST
PUT
PATCH
DELETE
HTTP forms the foundation of much of the modern web.
45. HTTP vs HTTPS?
Answer:
HTTPS is HTTP transmitted over a secure cryptographic connection, typically using TLS.
HTTPS provides:
- Encryption.
- Server authentication.
- Integrity protection.
Without encryption, attackers on an appropriate network path may be able to observe or manipulate traffic.
46. What is TCP?
Answer:
TCP is a connection-oriented transport protocol designed to provide reliable, ordered delivery.
It handles:
- Retransmission.
- Ordering.
- Flow control.
- Congestion control.
TCP is useful when reliable delivery is more important than minimizing protocol overhead.
47. What is UDP?
Answer:
UDP is a connectionless transport protocol with minimal overhead.
It does not inherently guarantee:
- Delivery.
- Ordering.
- Retransmission.
Applications such as real-time communication can use UDP when minimizing latency is more important than guaranteed delivery, often adding their own reliability mechanisms when needed.
48. TCP vs UDP?
Answer:
| TCP | UDP |
| Connection-oriented | Connectionless |
| Reliable delivery | No built-in delivery guarantee |
| Ordered data | No built-in ordering |
| More overhead | Lower overhead |
| Congestion control | Application-dependent |
The choice depends on application requirements rather than one protocol being universally better.
49. What is a Router?
Answer:
A router forwards packets between different networks.
It examines destination information and determines where packets should be forwarded.
For example:
Computer → Local Router → ISP → Internet
Routers are fundamental to inter-network communication.
50. What is a MAC Address?
Answer:
A MAC address is a link-layer hardware/interface identifier used within local networking technologies such as Ethernet.
An IP address primarily supports network-layer routing, while a MAC address is used for local link delivery.
Thus, they operate at different networking layers and serve different purposes.
Software Engineering
51. What is SDLC?
Answer:
SDLC stands for Software Development Life Cycle.
Typical stages include:
Requirements
↓
Design
↓
Development
↓
Testing
↓
Deployment
↓
Maintenance
The objective is to systematically transform requirements into reliable software.
52. What is Agile?
Answer:
Agile is an approach emphasizing iterative development, feedback, collaboration, and incremental delivery.
Instead of designing everything upfront and delivering at the end, teams frequently produce working increments.
This helps when requirements are likely to evolve.
53. What is Waterfall Model?
Answer:
Waterfall is a sequential development model where phases are generally completed in order.
It can work well when:
- Requirements are stable.
- Processes are highly regulated.
- Changes are expensive.
Its limitation is that discovering major requirement problems late can be costly.
54. What is Version Control?
Answer:
Version control tracks changes to source code and other project files.
Git is a widely used version-control system.
It enables:
- Branching.
- Merging.
- History tracking.
- Collaboration.
- Rollback.
Version control is essential for managing software changes safely.
55. What is Git?
Answer:
Git is a distributed version-control system.
Developers can maintain local repositories and synchronize changes with remote repositories.
Important concepts include:
Repository
Commit
Branch
Merge
Pull
Push
Git helps teams manage parallel development while preserving project history.
56. What is a Software Bug?
Answer:
A software bug is behavior that does not meet the intended requirements or expected behavior.
Bugs can originate from:
- Incorrect logic.
- Incorrect assumptions.
- Concurrency problems.
- Integration issues.
- Configuration errors.
Effective debugging involves reproducing the issue, isolating the cause, correcting it, and testing the fix.
57. What is Debugging?
Answer:
Debugging is the systematic process of identifying and correcting software defects.
A strong debugging approach is:
Observe
↓
Reproduce
↓
Isolate
↓
Form hypothesis
↓
Test hypothesis
↓
Fix
↓
Verify
This is more reliable than changing code randomly until the problem disappears.
58. What is Unit Testing?
Answer:
Unit testing tests small pieces of software independently.
For example:
calculateTax()
can be tested with multiple input values.
Unit tests help detect regressions early and make refactoring safer.
59. What is Integration Testing?
Answer:
Integration testing verifies whether multiple components work correctly together.
For example:
Application
↓
API
↓
Database
Each component may work independently but fail when integrated due to incompatible assumptions or interfaces.
60. What is Regression Testing?
Answer:
Regression testing checks whether previously working functionality still works after changes.
For example, fixing the payment module should not accidentally break order processing.
Automated regression tests are particularly valuable in frequently changing systems.
Data Structures and Algorithms
61. What is Binary Search?
Answer:
Binary search repeatedly divides a sorted search space into two halves.
For example:
1 3 5 7 9 11 13
To find 11, compare with the middle and eliminate the irrelevant half.
Its time complexity is:
O(log n)
The key requirement is that the search space must have an ordering property that allows half of it to be discarded.
62. What is Linear Search?
Answer:
Linear search checks elements sequentially.
For:
[4, 8, 2, 9, 7]
searching for 7 may require checking every element.
Worst-case complexity:
O(n)
It is simple and useful for small or unsorted datasets.
63. What is Recursion?
Answer:
Recursion occurs when a function calls itself to solve smaller versions of the same problem.
A recursive algorithm needs:
- Base case.
- Recursive case.
Example concept:
factorial(n)
→ n × factorial(n-1)
Recursion can simplify tree and divide-and-conquer algorithms, but excessive recursion can cause stack overflow.
64. What is Dynamic Programming?
Answer:
Dynamic programming solves problems by storing solutions to overlapping subproblems.
It is useful when a problem has:
- Overlapping subproblems.
- Optimal substructure.
Instead of recalculating:
F(5)
F(4)
F(3)
repeatedly, previously calculated results can be reused.
This can transform an exponential recursive solution into a polynomial-time solution in many cases.
65. What is Greedy Algorithm?
Answer:
A greedy algorithm makes the locally best choice at each step.
It can be efficient, but it is not universally correct.
For example, certain coin-change systems allow greedy selection to produce the optimal solution, while arbitrary denominations may not.
Therefore, the key analytical question is:
Can the problem be proven to have the greedy-choice property?
66. What is a Tree?
Answer:
A tree is a hierarchical data structure consisting of nodes and edges.
Common examples include:
- Binary trees.
- Binary search trees.
- Heaps.
- B-trees.
Trees are useful for representing hierarchical relationships and supporting specialized searching and ordering operations.
67. What is a Binary Search Tree?
Answer:
A Binary Search Tree follows an ordering property:
Left subtree < Node < Right subtree
If reasonably balanced, searching can approach:
O(log n)
But if the tree becomes highly skewed:
1
\
2
\
3
search can degrade to O(n).
Balanced trees address this issue.
68. What is a Heap?
Answer:
A heap is a tree-based structure satisfying a heap property.
In a min-heap:
Parent ≤ Children
The smallest element is at the root.
Heaps are useful for:
- Priority queues.
- Scheduling.
- Heap sort.
- Graph algorithms such as Dijkstra’s algorithm.
69. What is a Graph?
Answer:
A graph consists of vertices and edges representing relationships.
Examples:
People → friendships
Cities → roads
Web pages → hyperlinks
Graphs may be:
- Directed.
- Undirected.
- Weighted.
- Unweighted.
The representation and algorithm depend on the problem.
70. BFS vs DFS?
Answer:
BFS — Breadth-First Search
Explores level by level and typically uses a queue.
DFS — Depth-First Search
Explores deeply before backtracking and typically uses recursion or a stack.
For an unweighted graph, BFS can find the shortest path in terms of number of edges. DFS is often useful for structural exploration, cycle detection, and backtracking.
Computer Architecture
71. What is a CPU?
Answer:
The CPU executes instructions and performs computations.
Major conceptual components include:
- Control unit.
- Arithmetic Logic Unit.
- Registers.
- Cache-related mechanisms.
CPU performance depends on many factors, not just clock speed, including instruction-level parallelism, cache behavior, architecture, and workload.
72. What is RAM?
Answer:
RAM is volatile memory used to hold data and instructions actively needed by running programs.
RAM is much faster than persistent storage but loses its contents when power is removed.
More RAM can allow more programs and data to remain readily available, reducing reliance on slower storage.
73. What is Cache Memory?
Answer:
Cache is small, fast memory located close to the CPU.
Modern systems commonly have multiple cache levels:
L1 → L2 → L3 → RAM → Storage
The closer the data is to the CPU, the lower the access latency tends to be.
Cache efficiency depends heavily on temporal and spatial locality.
74. What is a CPU Core?
Answer:
A CPU core is an independent processing unit capable of executing instructions.
A multi-core CPU can execute multiple instruction streams concurrently.
However, having more cores does not automatically make every program proportionally faster because software must contain sufficient parallelizable work.
75. What is a Compiler?
Answer:
A compiler translates source code into another form, commonly machine code or intermediate code.
A simplified process is:
Source Code
↓
Lexical Analysis
↓
Parsing
↓
Semantic Analysis
↓
Optimization
↓
Code Generation
Compiler optimization attempts to improve performance while preserving program behavior.
76. Compiler vs Interpreter?
Answer:
A compiler generally translates code before execution, while an interpreter executes through a runtime mechanism.
Modern language implementations often combine approaches.
For example, a system may use:
Source
↓
Bytecode / Intermediate Representation
↓
Virtual Machine
↓
JIT Compilation
Therefore, the distinction is more nuanced than simply “compiled versus interpreted.”
77. What is Machine Code?
Answer:
Machine code consists of instructions that a particular processor architecture can execute directly.
Different CPU architectures use different instruction sets.
For example:
x86
ARM
RISC-V
Therefore, machine code is architecture-dependent.
78. What is an Instruction Set Architecture?
Answer:
ISA defines the instructions and programmer-visible behavior supported by a processor.
Examples include:
- x86-64
- ARM
- RISC-V
The ISA acts as an interface between software and processor implementation.
Different processors can implement the same ISA internally in very different ways.
79. What is Parallel Processing?
Answer:
Parallel processing divides work so multiple computations can happen simultaneously.
For example:
Task
├── Part A → Core 1
├── Part B → Core 2
├── Part C → Core 3
└── Part D → Core 4
The theoretical speedup depends on how much of the task can actually be parallelized.
80. What is a GPU?
Answer:
A GPU is a processor architecture designed to perform many operations in parallel.
GPUs are particularly effective for workloads involving large numbers of similar computations, such as:
- Graphics.
- Matrix operations.
- Scientific computing.
- Machine learning.
They are not automatically better than CPUs for every workload because branching, sequential dependencies, and data movement can reduce GPU efficiency.
Web and Software Development
81. What is an API?
Answer:
An API, or Application Programming Interface, defines how software components communicate.
For example:
Mobile App
↓
API
↓
Server
↓
Database
APIs provide abstraction: the client does not need to know how the server internally processes the request.
82. What is REST?
Answer:
REST is an architectural style commonly used for web APIs.
Typical REST APIs use HTTP methods such as:
GET
POST
PUT
DELETE
Resources are represented through URLs.
A major REST principle is stateless interaction, where each request contains the information necessary for the server to process it.
83. What is JSON?
Answer:
JSON stands for JavaScript Object Notation.
Example:
{
“name”: “John”,
“age”: 25
}
JSON is popular for APIs because it is relatively simple for humans to read and easy for programs to parse.
84. What is Authentication?
Answer:
Authentication determines who a user is.
Examples include:
- Passwords.
- One-time codes.
- Security keys.
- Biometrics.
Authentication should be distinguished from authorization.
85. What is Authorization?
Answer:
Authorization determines what an authenticated user is allowed to do.
For example:
User → Read articles
Admin → Read + Edit + Delete
Authentication answers:
“Who are you?”
Authorization answers:
“What are you allowed to access?”
86. What is a Cookie?
Answer:
A cookie is a small piece of data stored by a browser and associated with a website.
Cookies can be used for:
- Session management.
- Preferences.
- Authentication-related state.
- Analytics.
Security-sensitive cookies should use appropriate attributes such as Secure, HttpOnly, and suitable SameSite settings.
87. What is a Session?
Answer:
A session represents state associated with a user’s interaction with an application.
For example:
Login
↓
Session created
↓
User accesses multiple pages
↓
Session expires/logout
Sessions allow applications to maintain continuity across otherwise separate HTTP requests.
88. What is Caching?
Answer:
Caching stores frequently accessed data closer to where it is needed.
Example:
Database
↓
Cache
↓
Application
If data is available in the cache, the application may avoid an expensive database query.
The challenge is maintaining appropriate freshness and handling cache invalidation.
89. What is Load Balancing?
Answer:
Load balancing distributes incoming requests across multiple servers.
Example:
Users
↓
Load Balancer
↙ ↓ ↘
S1 S2 S3
This can improve:
- Scalability.
- Availability.
- Resource utilization.
The balancing strategy must account for factors such as server capacity and session requirements.
90. What is Scalability?
Answer:
Scalability is the ability of a system to handle increasing workload.
Two common approaches are:
Vertical scaling: Increase the resources of one machine.
Horizontal scaling: Add more machines.
For large distributed systems, horizontal scaling can provide greater capacity and resilience, but it introduces additional coordination complexity.
Cybersecurity
91. What is Encryption?
Answer:
Encryption transforms readable data into ciphertext using a cryptographic algorithm and key.
Conceptually:
Plaintext
↓ Encryption
Ciphertext
↓ Decryption
Plaintext
Modern encryption aims to make unauthorized recovery computationally impractical without the required key.
92. Symmetric vs Asymmetric Encryption?
Answer:
Symmetric encryption
- Uses the same secret key for encryption and decryption.
- Generally efficient for large amounts of data.
Asymmetric cryptography
- Uses a public/private key pair.
- Useful for key exchange, authentication, and digital signatures.
Modern secure systems often combine both approaches.
93. What is a Hash Function?
Answer:
A cryptographic hash function maps input data to a fixed-size output.
Example:
Password → Hash
A secure cryptographic hash should make it computationally difficult to recover the original input from the hash.
Password systems should additionally use dedicated password-hashing algorithms with salts and appropriate work factors rather than simple general-purpose hashes.
94. What is SQL Injection?
Answer:
SQL injection occurs when untrusted input is incorrectly incorporated into SQL queries.
For example, constructing SQL by string concatenation can allow input to alter the intended query.
The primary defense is parameterized queries/prepared statements.
Input validation, least privilege, and secure database configuration provide additional protection.
95. What is Cross-Site Scripting?
Answer:
Cross-Site Scripting, or XSS, occurs when untrusted content is executed as script in a user’s browser.
Potential consequences include:
- Session-related attacks.
- Unauthorized actions.
- Data exposure.
Important defenses include contextual output encoding, safe templating, input handling, and an appropriately configured Content Security Policy.
96. What is a Firewall?
Answer:
A firewall controls network traffic according to predefined security rules.
It may filter traffic based on factors such as:
- IP address.
- Port.
- Protocol.
- Connection state.
- Application characteristics.
A firewall reduces the attack surface but is not a complete security solution.
97. What is Malware?
Answer:
Malware is malicious software designed to perform unauthorized or harmful actions.
Examples include:
- Viruses.
- Worms.
- Trojans.
- Ransomware.
- Spyware.
Effective defense requires multiple layers, including secure configuration, patching, endpoint protection, backups, access controls, and user awareness.
98. What is the Principle of Least Privilege?
Answer:
Least privilege means giving users, applications, and systems only the permissions necessary to perform their tasks.
For example, an application that only needs to read customer information should not receive unrestricted database administrator privileges.
If an account is compromised, least privilege limits potential damage.
Advanced Interview Questions
99. How would you design a scalable web application?
Answer:
A reasonable high-level architecture could be:
Users
↓
CDN / Load Balancer
↓
Web/Application Servers
↓
Cache
↓
Database
As traffic grows, we can:
- Add more application servers.
- Introduce load balancing.
- Cache frequently accessed data.
- Optimize database queries.
- Add appropriate indexes.
- Use read replicas where suitable.
- Move static assets to a CDN.
- Introduce asynchronous processing for long-running tasks.
- Monitor performance and failures.
The key analytical principle is to identify the actual bottleneck before adding infrastructure. Scaling every component unnecessarily increases cost and complexity.
100. How would you approach solving a difficult programming problem in an interview?
Answer:
A strong approach is:
Step 1 — Understand the problem
Clarify:
- Input.
- Output.
- Constraints.
- Edge cases.
Step 2 — Create examples
For example:
Input → [2, 7, 11, 15]
Target → 9
Output → [0, 1]
Step 3 — Start with a simple solution
First establish a correct brute-force approach.
Step 4 — Analyze complexity
Ask:
Can O(n²) become O(n)?
Can additional memory reduce execution time?
Can sorting help?
Can hashing help?
Step 5 — Optimize
Choose an appropriate data structure or algorithm.
Step 6 — Test edge cases
Consider:
- Empty input.
- One element.
- Duplicate values.
- Very large input.
- Negative values.
- Already sorted data.
Step 7 — Explain trade-offs
For example:
“This solution uses O(n) extra memory to reduce the time complexity from O(n²) to O(n).”

100 Computer Science Interview Questions