Describe the process of balancing a binary search tree (BST). Why is it important?

  • Checking and adjusting node heights.
  • Ensuring that the left subtree is balanced, and the right subtree is balanced. Maintaining the BST property.
  • Performing tree rotations and reorganizing nodes to maintain optimal search times.
  • Rotating nodes to maintain balance.
Balancing a binary search tree is crucial for maintaining efficient search operations. Unbalanced trees can lead to degraded performance, causing search times to increase significantly. By balancing the tree, we ensure that search operations remain logarithmic in time complexity, thus optimizing performance.

How does JavaScript handle asynchronous operations, and what are the various methods for handling them?

  • Async/await
  • Callbacks
  • Observables
  • Promises
JavaScript handles asynchronous operations using various methods. Callbacks were one of the earliest ways to handle asynchronous code but can lead to callback hell. Promises provide a more structured way to handle asynchronous operations, allowing chaining and error handling. Async/await is a more recent addition, offering a more synchronous-looking syntax for writing asynchronous code. Observables are part of the RxJS library and are used for handling streams of data asynchronously.

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.

What is the difference between deadlock prevention and deadlock avoidance?

  • Detecting and breaking deadlock once it occurs
  • Preventing resource allocation patterns that lead to deadlock
  • Proactively avoiding deadlock by resource allocation strategies
  • Reactively resolving deadlock situations after they occur
The key difference between deadlock prevention and deadlock avoidance lies in their approaches to handling deadlock situations in operating systems. Deadlock prevention focuses on proactively avoiding deadlock by implementing resource allocation strategies and system design techniques that eliminate the possibility of deadlock occurrence. On the other hand, deadlock avoidance aims to reactively resolve deadlock situations after they occur by detecting them and taking appropriate actions, such as preempting resources or terminating processes to break the deadlock. While prevention aims to stop deadlock from happening in the first place, avoidance deals with managing deadlocks if they occur, making them complementary strategies in ensuring system stability and resource utilization efficiency.

In a distributed system, you need to efficiently search for a particular value across multiple sorted arrays. How would you approach this problem?

  • Binary Search
  • Hashing
  • Indexing
  • Linear Search
Binary Search is the optimal approach for searching in sorted arrays due to its logarithmic time complexity O(log n). Linear Search is inefficient for large datasets, Hashing may not be suitable for sorted arrays, and Indexing might introduce additional overhead in a distributed system.

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.