What is the primary purpose of Dijkstra's algorithm?

  • Finding the shortest path between two nodes in a graph
  • Generating random numbers
  • Sorting elements in an array
  • Traversing a linked list
The primary purpose of Dijkstra's algorithm is to find the shortest path between two nodes in a graph, particularly in a graph with non-negative edge weights. It is commonly used in routing and network protocols.

How does linear search perform on sorted versus unsorted arrays?

  • Better on sorted arrays
  • Better on unsorted arrays
  • Equally efficient on both
  • Performs differently based on array length
Linear search performs better on sorted arrays. This is because, in a sorted array, once a value greater than the target is encountered, the search can stop, resulting in early termination. On the other hand, in an unsorted array, the search continues until the target is found or the entire array is traversed.

BFS explores all nodes at the _______ level before moving to the next level.

  • Next
  • Previous
  • Random
  • Same
BFS explores all nodes at the same level before moving to the next level. This ensures that the algorithm covers all nodes at a particular level before proceeding to the subsequent level in a graph traversal.

You are developing a plagiarism detection system for a large document database. Which pattern matching algorithm would you choose and why?

  • Boyer-Moore Algorithm
  • Knuth-Morris-Pratt (KMP) Algorithm
  • Naive Pattern Matching
  • Rabin-Karp Algorithm
For a plagiarism detection system in a large document database, the Rabin-Karp algorithm would be a suitable choice. It utilizes hashing to efficiently detect patterns, making it well-suited for identifying similarities in documents by comparing hash values.

What problem does the Ford-Fulkerson algorithm aim to solve?

  • Counting the number of strongly connected components in a directed graph.
  • Determining the minimum spanning tree of a graph.
  • Finding the shortest path in a graph.
  • Solving the maximum flow problem in a network.
The Ford-Fulkerson algorithm aims to solve the maximum flow problem in a network, where the goal is to find the maximum amount of flow that can be sent from a designated source to a designated sink in a flow network.

What is the time complexity of the selection sort algorithm in the worst-case scenario?

  • O(log n)
  • O(n log n)
  • O(n)
  • O(n^2)
The worst-case time complexity of the selection sort algorithm is O(n^2), where 'n' is the number of elements in the array. This is due to the nested loops used to find the minimum element in each iteration.

Consider a scenario where you need to search for a specific item in an unsorted list that is constantly changing. Discuss the advantages and disadvantages of using linear search in this situation.

  • Binary search
  • Hashing
  • Jump search
  • Linear search
In a scenario with an unsorted list that is constantly changing, linear search has the advantage of simplicity. However, its time complexity of O(n) may lead to inefficiency as the list size grows. Advantages include ease of implementation, but disadvantages involve potentially slower performance compared to other algorithms like hashing or jump search, which can exploit certain characteristics of the data for faster retrieval.

It ensures finding the shortest path by maintaining a _______ that contains the shortest distance to each node from the source.

  • Binary Tree
  • Linked List
  • Priority Queue
  • Stack
It ensures finding the shortest path by maintaining a priority queue that contains the shortest distance to each node from the source. The priority queue helps prioritize nodes based on their distance values, facilitating efficient path exploration.

Can regular expressions be used to validate email addresses? Explain.

  • Email address validation requires manual checking and cannot be automated with regular expressions.
  • No, regular expressions are not suitable for email address validation.
  • Regular expressions can only validate numeric values, not textual data like email addresses.
  • Yes, regular expressions can be used to validate email addresses by defining a pattern that checks for the required components like username, domain, and top-level domain (TLD).
Regular expressions can indeed be used to validate email addresses. The pattern can be crafted to ensure the presence of a valid username, domain, and top-level domain (TLD), adhering to the typical structure of email addresses.

Consider a scenario where you're designing a water distribution network with multiple sources and sinks. How would you adapt the Ford-Fulkerson algorithm to efficiently manage flow in this network?

  • Apply the Ford-Fulkerson algorithm to maximize water flow across the network without considering the efficiency of distribution.
  • Implement the Ford-Fulkerson algorithm to balance water flow efficiently among multiple sources and sinks, adjusting capacities based on demand.
  • Use the Ford-Fulkerson algorithm to randomly allocate water flow to sources and sinks in the distribution network.
  • Utilize the Ford-Fulkerson algorithm to prioritize water flow from one specific source to all sinks in the network.
In the water distribution network scenario, the Ford-Fulkerson algorithm is adapted to efficiently manage flow by balancing water distribution among multiple sources and sinks. Capacities are adjusted based on demand, optimizing the overall flow in the network.