When should you avoid using dynamic programming to solve a problem?
- When the problem can be solved using a greedy algorithm.
- When the problem can be solved using recursion efficiently.
- When the problem does not have overlapping subproblems.
- When the problem has a small input size.
Dynamic programming is most effective when a problem exhibits overlapping subproblems, meaning the same subproblems are solved multiple times in the process. If a problem does not have this characteristic, dynamic programming may not offer significant advantages over other approaches like recursion or greedy algorithms. Additionally, for problems with very small input sizes, the overhead of dynamic programming (such as building tables or memoization arrays) might outweigh the benefits, making simpler algorithms more suitable.
What is a deadlock in the context of multithreading?
- A process terminates unexpectedly
- A situation where two or more processes wait indefinitely for resources held by each other
- A thread accesses a resource without permission
- A thread executes slower than expected
A deadlock occurs in multithreading when two or more threads are unable to proceed because each is waiting for the other to release a resource, resulting in a standstill where no progress can be made. This can lead to system hangs or crashes.
Explain the CAP theorem and its relevance to NoSQL databases.
- CAP theorem states that a distributed system can simultaneously provide Consistency, Availability, and Partition tolerance.
- CAP theorem states that a distributed system cannot simultaneously provide Consistency, Availability, and Partition tolerance.
- CAP theorem states that a distributed system prioritizes Availability over Consistency and Partition tolerance.
- CAP theorem states that a distributed system prioritizes Consistency over Availability and Partition tolerance.
The CAP theorem is crucial in understanding the limitations of distributed systems. It states that in the presence of a network partition, a distributed system can only guarantee either Consistency or Availability, not both. NoSQL databases often sacrifice Consistency (CP) for better Availability and Partition tolerance (AP).
Explain the difference between mutex and semaphore.
- Binary
- Counting
- Mutual Exclusion
- Synchronization
Mutex and semaphore are both synchronization mechanisms, but they serve different purposes. A mutex ensures mutual exclusion, allowing only one thread to access a resource at a time, while a semaphore can allow multiple threads to access multiple resources concurrently. Mutexes typically use binary values (0 and 1) to signal resource availability, while semaphores can have a count greater than 1, allowing for resource allocation based on available counts.
IPv6 uses ________-bit addresses compared to IPv4's 32-bit addresses.
- 64
- 128
- 256
- 512
IPv6 uses 128-bit addresses, which is a significant increase from IPv4's 32-bit addresses. This expansion allows for a much larger number of possible unique addresses, addressing the issue of IPv4 address exhaustion. Therefore, "128" is the correct option.
You're designing a database for a university. How would you apply normalization techniques to ensure efficient data storage and retrieval, considering the various entities involved such as students, courses, and instructors?
- Break the data into multiple tables and use foreign keys
- Store all information in one table
- Use denormalization techniques
- Use multiple databases for each entity
Normalization involves breaking down data into multiple tables and using relationships like foreign keys to link them together. This ensures data is not duplicated, reduces redundancy, and allows for efficient querying and data retrieval. Storing all information in one table would lead to data redundancy and inefficiency. Using multiple databases or denormalization would not adhere to normalization principles.
How does a semaphore differ from a mutex in terms of signaling and resource access?
- Binary
- Counting
- Deadlock
- Thread blocking
Semaphores and mutexes differ in signaling and resource access. A semaphore can handle multiple resources by using a counting mechanism, allowing multiple threads to access resources concurrently. It uses signals to manage resource availability. On the other hand, a mutex is binary, meaning it only allows one thread access to a resource at a time, using a blocking mechanism to prevent other threads from accessing the resource until it's released.
Which scheduling algorithm ensures fairness among processes in terms of CPU allocation?
- First Come First Serve (FCFS)
- Priority Scheduling
- Round Robin
- Shortest Job Next (SJN)
Priority Scheduling ensures fairness by assigning priorities to processes based on criteria such as importance or resource requirements. This ensures that critical tasks get appropriate CPU time, promoting fairness.
You're tasked with securing a corporate network against insider threats. How would you implement strategies to prevent unauthorized access to sensitive data?
- Conduct regular security awareness training for employees
- Implement multi-factor authentication (MFA)
- Implement strict access control policies
- Utilize encryption techniques for data at rest and in transit
Multi-factor authentication (MFA) adds an extra layer of security by requiring users to provide multiple forms of identification before accessing sensitive data. This can prevent unauthorized access even if login credentials are compromised. Strict access control policies limit access based on roles and responsibilities, reducing the risk of unauthorized access. Security awareness training educates employees about potential threats and best practices, but it alone may not prevent unauthorized access. Encryption protects data from being accessed by unauthorized parties, but it doesn't prevent access attempts.
___________ is a design principle in OOP that states a class should have only one reason to change.
- Encapsulation
- Inheritance
- Polymorphism
- Single Responsibility Principle
The correct option is Single Responsibility Principle. This principle suggests that a class should have only one job or reason to change, leading to more modular, maintainable, and understandable code.