Designed for aspiring software engineers and developers, this category features questions on data structures, algorithms, object-oriented programming, and system design. It includes coding challenges and real-world scenarios to test your problem-solving abilities. From C++ to Python, and from recursion to database management, these questions cover the essentials to help you excel in technical interviews.
Answer: A stack is a LIFO (Last In, First Out) data structure, while a queue is a FIFO (First In, First Out) data structure.
Answer: A hash table stores key-value pairs and uses a hash function to compute an index for storing data. Common hashing techniques include division method, multiplication method, and universal hashing.
Answer: O(log n)
Answer: Merge sort is a divide-and-conquer algorithm that splits the array, sorts each part, and merges them. Its time complexity is O(n log n).
Answer: A heap is a complete binary tree. In a min-heap, the parent node is smaller than its children; in a max-heap, the parent node is larger.
Answer: By iterating through the list and changing the next pointers to point to the previous nodes.
Answer: Arrays have fixed size and provide O(1) access, while linked lists are dynamic and have O(n) access time but allow O(1) insertions/deletions.
Answer: Dynamic programming stores intermediate results to avoid redundant calculations, whereas recursion solves problems by repeatedly breaking them into smaller subproblems.
Answer: A BST is a binary tree where each node has a key, and the left subtree contains keys smaller than the root, while the right subtree contains keys larger.
Answer: By using a priority queue to repeatedly select the vertex with the smallest distance and updating the distances of its neighbors.
Answer: DFS explores as far as possible along a branch before backtracking, while BFS explores all neighbors before moving deeper.
Answer: Yes, using two stacks: one for enqueuing and one for dequeuing.
Answer: By using chaining (linked lists) or open addressing (linear probing, quadratic probing, double hashing).
Answer: O(log n)
Answer: By using Depth First Search (DFS) with a visited and recursion stack.
Answer: Kruskal's algorithm sorts all edges and adds them one by one to the spanning tree, ensuring no cycles.
Answer: The KMP algorithm efficiently finds patterns in a string by preprocessing the pattern to avoid unnecessary comparisons.
Answer: By ensuring the height difference between left and right subtrees for every node is at most 1.
Answer: Tail recursion occurs when the recursive call is the last operation in the function.
Answer: Greedy algorithms make locally optimal choices, while dynamic programming solves problems by considering all possibilities and using overlapping subproblems.
Answer: By using a binary heap where the root is always the highest (max-heap) or lowest (min-heap) priority element.
Answer: Memoization stores results of expensive function calls to avoid redundant computations.
Answer: Quick sort partitions the array into two parts and sorts them recursively. Average time complexity is O(n log n); worst-case is O(n^2).
Answer: It is the average time per operation over a sequence of operations. Used in dynamic arrays and hash tables.
Answer: By using a heap or the Quickselect algorithm.
Answer: Process scheduling determines the execution order of processes. Types include long-term, short-term, and medium-term schedulers.
Answer: Virtual memory uses disk space as an extension of RAM, allowing processes to execute beyond physical memory limits.
Answer: Deadlock is a situation where processes wait indefinitely for resources. Prevention includes resource ordering and avoiding circular waits.
Answer: A process is an independent executing instance, while a thread is a lightweight unit of execution within a process.
Answer: Round Robin assigns time slices to processes in a cyclic order, ensuring fair CPU time distribution.
Answer: Paging divides memory into fixed-size blocks, while segmentation divides it into variable-size logical segments.
Answer: Race conditions occur when multiple threads access shared resources simultaneously. They can be avoided using locks, mutexes, or semaphores.
Answer: The banker's algorithm ensures resources are allocated safely by checking if allocation would leave the system in a safe state.
Answer: Preemptive scheduling allows process interruption, while non-preemptive scheduling completes a process before switching.
Answer: A system call is a user-space request to the kernel for services like file operations or process control.
Answer: Multitasking runs multiple processes, while multithreading runs multiple threads within a process.
Answer: Context switching is saving a process state and restoring another. It occurs during process scheduling or interrupts.
Answer: A mutex ensures only one thread accesses a critical section at a time to prevent race conditions.
Answer: IPC allows processes to exchange data using mechanisms like shared memory, message passing, or pipes.
Answer: Monolithic kernels manage all OS functions, while microkernels handle core services, delegating others to user space.
Answer: Demand paging loads pages into memory only when needed, reducing memory usage.
Answer: Inodes store metadata about files, like size, permissions, and disk block locations.
Answer: Paging moves memory pages between RAM and disk, while swapping moves entire processes.
Answer: Thrashing occurs when excessive paging reduces performance. It can be avoided by allocating sufficient memory or adjusting multiprogramming levels.
Answer: Signal handlers execute specific functions when a process receives a signal, overriding default behavior.
Answer: Starvation occurs when low-priority processes are indefinitely delayed. It can be resolved using aging to increase priority over time.
Answer: Priority inversion occurs when a high-priority task waits for a lower-priority task. Solutions include priority inheritance.
Answer: The scheduler manages CPU allocation to processes, optimizing performance and resource utilization.
Answer: Process synchronization uses mechanisms like locks, semaphores, and monitors to ensure safe shared resource access.
Answer: Process states include new, ready, running, waiting, and terminated.
Answer: Normalization organizes data to reduce redundancy and improve data integrity.
Answer: ACID stands for Atomicity, Consistency, Isolation, and Durability, ensuring reliable transactions.
Answer: A foreign key links tables and references a primary key in another table; a primary key uniquely identifies a record.
Answer: SQL databases are relational and use structured schemas, while NoSQL databases are non-relational and handle unstructured data.
Answer: By indexing, analyzing query plans, optimizing joins, and avoiding SELECT *.
Answer: Isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) define how transactions interact with each other.
Answer: Triggers are automatic actions executed in response to certain database events.
Answer: Indexing creates a data structure to allow faster search and retrieval.
Answer: Partitioning divides data into smaller segments for improved manageability and performance.
Answer: JOIN combines data from multiple tables. Types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.
Answer: A view is a virtual table based on a query, whereas a table physically stores data.
Answer: WHERE filters rows before aggregation; HAVING filters after aggregation.
Answer: Stored procedures perform tasks and can return multiple values, while functions return a single value.
Answer: Sharding partitions data across multiple servers for scalability.
Answer: Deadlock occurs when transactions wait indefinitely for resources. It can be resolved by timeouts or deadlock detection algorithms.
Answer: A schema defines the structure of a database, including tables, columns, and relationships.
Answer: Cascading deletes automatically remove dependent rows when a referenced row is deleted.
Answer: Denormalization combines tables to improve read performance, often used in analytics.
Answer: By using LIMIT and OFFSET or ROW_NUMBER.
Answer: Locks prevent concurrent access issues. Types include shared, exclusive, and row-level locks.
Answer: Aggregate functions perform calculations on multiple rows. Examples: COUNT(), AVG(), MAX(), MIN(), SUM().
Answer: By using foreign keys with constraints like ON DELETE and ON UPDATE.
Answer: Horizontal scaling adds more servers; vertical scaling increases server capacity.
Answer: Replication copies data from one server to others for redundancy and scalability.
Answer: Inheritance allows one class to derive properties and behaviors from another. Example: A Dog class inherits from an Animal class.
Answer: Polymorphism allows one interface with multiple implementations; overloading defines multiple methods with the same name but different parameters.
Answer: Abstract classes can have implementations; interfaces only define methods without implementation.
Answer: Encapsulation restricts direct access to an object's data, exposing only necessary parts.
Answer: Constructor chaining occurs when one constructor calls another in the same or a parent class.
Answer: By using interfaces.
Answer: The diamond problem occurs with multiple inheritance when a class inherits the same base class via different paths. It is resolved using virtual inheritance or interfaces.
Answer: Overriding changes a method's behavior in a subclass; overloading defines multiple methods with the same name but different parameters.
Answer: Design patterns are reusable solutions to common problems. Singleton ensures a class has only one instance.
Answer: SOLID principles ensure maintainable and scalable OOP designs: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.
Answer: Composition implies ownership and lifecycle management; aggregation does not.
Answer: Late binding resolves method calls at runtime, allowing dynamic method invocation.
Answer: Dependency injection provides objects their dependencies, improving testability and modularity.
Answer: Access modifiers control visibility. Public: accessible everywhere; Private: within the class; Protected: within the class and subclasses.
Answer: Using try-catch blocks, custom exceptions, and finally blocks.
Answer: A virtual function allows method overriding in derived classes for runtime polymorphism.
Answer: Subtypes must be substitutable for their base types without altering functionality.
Answer: Garbage collection automatically reclaims memory by identifying and removing unused objects.
Answer: Shallow copy copies references, not objects; deep copy duplicates objects entirely.
Answer: Static binding occurs at compile time, binding methods to calls based on the declared type.
Answer: Duck typing determines object compatibility based on methods and properties rather than inheritance.
Answer: The OSI model has 7 layers: Physical, Data Link, Network, Transport, Session, Presentation, Application, each handling specific network functions.
Answer: TCP is connection-oriented and reliable; UDP is connectionless and faster but less reliable.
Answer: HTTP is a request-response protocol. Status codes indicate the response type (e.g., 200 OK, 404 Not Found).
Answer: DNS translates domain names to IP addresses using a hierarchical lookup.
Answer: IP addressing assigns unique identifiers; subnetting divides networks into smaller segments for efficient use.
Answer: ARP maps IP addresses to MAC addresses in a local network.
Answer: IPv4 uses 32-bit addresses; IPv6 uses 128-bit addresses and offers better scalability and security.
Answer: A firewall filters network traffic; a proxy acts as an intermediary for requests.
Answer: SSL/TLS encrypts data in transit for secure communication.
Answer: A router connects networks; a switch connects devices within a network.
Answer: Congestion control manages data flow to prevent overwhelming the network.
Answer: NAT translates private IP addresses to a public IP, conserving IP addresses.
Answer: Load balancers distribute traffic across multiple servers to ensure availability and performance.
Answer: ICMP diagnoses network issues, sending error messages (e.g., ping).
Answer: A VPN secures communication over the internet; a VLAN groups devices in a virtual network.
Was this helpful?