What is the primary advantage of selection sort over bubble sort?

  • Less data movement
  • More adaptable
  • Space complexity is lower
  • Time complexity is lower
The primary advantage of selection sort over bubble sort is that it has less data movement. While both have the same time complexity of O(n^2), selection sort performs fewer swaps, making it more efficient in scenarios where minimizing data movement is crucial.

In the context of the longest common substring problem, what does "substring" refer to?

  • A contiguous sequence of characters within a string.
  • A sequence of characters obtained by rearranging the characters of a string.
  • A sequence of characters that appears exactly once in a string.
  • Any sequence of characters, regardless of their arrangement, within a string.
In the context of the longest common substring problem, a "substring" refers to a contiguous sequence of characters within a string. It can be of any length and must appear in the same order as it does in the original string.

Edit Distance is particularly useful in _______ processing tasks, such as automatic summarization and _______ recognition.

  • Image, Speech
  • Natural Language, Image
  • Speech, Natural Language
  • Text, Speech
Edit Distance is particularly useful in text processing tasks, such as automatic summarization and speech recognition. It quantifies the similarity between two strings by measuring the minimum number of single-character edits required to change one string into the other.

In a priority queue, elements are retrieved based on their _______ rather than their order of insertion.

  • Position
  • Priority
  • Size
  • Value
In a priority queue, elements are retrieved based on their priority rather than their order of insertion. Elements with higher priority are processed before those with lower priority, allowing for flexible ordering based on specific criteria.

In the Ford-Fulkerson algorithm, the _______ graph is used to represent remaining capacity in the network.

  • Bipartite
  • Residual
  • Spanning
  • Weighted
In the Ford-Fulkerson algorithm, the residual graph is used to represent the remaining capacity in the network. It is an auxiliary graph that helps track the available capacity for flow augmentation.

When the two strings have different lengths, the Edit Distance algorithm handles the disparity by considering the shorter string's _______ as having additional characters appended to it.

  • End, Middle
  • Middle, End
  • Prefix, Suffix
  • Suffix, Prefix
When the two strings have different lengths, the Edit Distance algorithm handles the disparity by considering the shorter string's suffix as having additional characters appended to it. This allows for a proper comparison between strings of varying lengths.

How does the concept of recursion relate to stack data structure? Provide examples to illustrate.

  • Recursion and stack data structure are unrelated concepts and do not interact with each other.
  • Recursion involves calling a function within itself until a base condition is met, leading to the creation of a stack frame for each recursive call.
  • Recursion relies on arrays to store function calls and manage recursive operations, eliminating the need for a stack data structure.
  • Recursion utilizes queues instead of stacks to manage function calls and handle recursive operations efficiently.
Recursion and stack data structure are closely related concepts. In recursive function calls, each function call creates a new stack frame, which contains information about the function's parameters, local variables, and return address. This stack-based mechanism allows recursive functions to maintain separate instances of local variables and control flow for each invocation, ensuring proper function execution and memory management. For example, consider the recursive implementation of factorial function, where each recursive call creates a new stack frame until the base case is reached.

How does A* search handle the trade-off between cost and heuristic estimate?

  • It always prioritizes cost over the heuristic
  • It ignores the trade-off completely
  • It randomly selects either cost or heuristic
  • It uses a weighted sum of cost and heuristic (f = g + w * h)
A* search handles the trade-off by using a weighted sum of cost and heuristic, denoted as f = g + w * h, where 'g' is the actual cost from the start state, 'h' is the heuristic estimate, and 'w' is a weight factor. Adjusting the weight influences the balance between cost and heuristic in the decision-making process.

What is the difference between a static array and a dynamic array?

  • Dynamic arrays are faster in accessing elements compared to static arrays.
  • Dynamic arrays are only used in dynamic programming languages, whereas static arrays are used in statically-typed languages.
  • Static arrays are more memory-efficient than dynamic arrays.
  • Static arrays have a fixed size that cannot be changed during runtime, while dynamic arrays can resize themselves as needed.
The key difference between a static array and a dynamic array is that a static array has a fixed size set at compile-time, whereas a dynamic array can dynamically resize itself during runtime. Static arrays are typically used in languages like C, while dynamic arrays are common in languages like Python and Java.

Suppose you are working on optimizing a supply chain management system. Discuss how the Longest Increasing Subsequence problem could be employed to streamline inventory management.

  • Apply the Longest Increasing Subsequence to randomly rearrange inventory for better visibility.
  • Implement the Longest Increasing Subsequence to prioritize inventory based on alphabetical order.
  • Use the Longest Increasing Subsequence to identify patterns in demand and adjust inventory levels accordingly.
  • Utilize the Longest Increasing Subsequence to categorize products for marketing purposes.
In optimizing a supply chain management system, the Longest Increasing Subsequence can be employed to streamline inventory management by identifying patterns in demand. This enables better forecasting and adjustment of inventory levels to meet customer needs efficiently.

In Kruskal's algorithm, the _______ data structure is often employed to efficiently detect cycles.

  • Disjoint-set
  • Heap
  • Queue
  • Stack
In Kruskal's algorithm, the disjoint-set data structure, also known as the union-find data structure, is often employed to efficiently detect cycles in the graph. This allows the algorithm to avoid adding edges that would create cycles in the minimum spanning tree.

Discuss the advantages and disadvantages of Dijkstra's algorithm compared to Bellman-Ford and Floyd-Warshall algorithms.

  • Bellman-Ford is always preferable due to its efficiency in handling negative edge weights. Dijkstra's algorithm is the best choice for all scenarios. Floyd-Warshall should only be used for small graphs.
  • Dijkstra's algorithm is faster but doesn't handle negative edge weights well. Bellman-Ford handles negative weights but has higher time complexity. Floyd-Warshall is efficient for dense graphs but may be slower for sparse graphs.
  • Dijkstra's algorithm is the only one suitable for graphs with negative cycles.
  • Floyd-Warshall is always faster than Dijkstra's and Bellman-Ford algorithms. Dijkstra's algorithm is the most efficient for all graph types.
Dijkstra's algorithm has the advantage of being faster than Bellman-Ford and Floyd-Warshall for sparse graphs but struggles with negative edge weights. Bellman-Ford handles negative weights but has higher time complexity. Floyd-Warshall is efficient for dense graphs but may be slower for sparse graphs. The choice depends on the specific characteristics of the graph and the importance of negative weights.