What is the main difference between Prim's and Kruskal's algorithms?

  • Kruskal's algorithm always selects the edge with the maximum weight.
  • Kruskal's algorithm starts with an arbitrary vertex and grows the minimum spanning tree from there.
  • Prim's algorithm builds the minimum spanning tree one vertex at a time, while Kruskal's algorithm builds it one edge at a time.
  • Prim's algorithm uses a greedy approach and always selects the vertex with the minimum key value.
The main difference between Prim's and Kruskal's algorithms is in their approach to building the minimum spanning tree. Prim's algorithm grows the tree one vertex at a time, always selecting the vertex with the minimum key value, while Kruskal's algorithm grows the tree one edge at a time by selecting the smallest available edge.

Consider a scenario where you have a graph representing a network of cities connected by roads with tolls. Discuss the modifications needed to adapt Dijkstra's algorithm to find the shortest path while considering both distance and toll costs.

  • Add toll costs to the edge weights
  • Exclude edges with tolls from the graph
  • Ignore toll costs and focus only on the distance
  • Prioritize routes with the fewest toll booths
To adapt Dijkstra's algorithm for toll costs, you should add toll costs to the edge weights. This modification ensures that the algorithm considers both distance and toll costs when finding the shortest path, providing a more accurate representation of the actual travel expenses.

Manacher's Algorithm utilizes _______ and _______ arrays to efficiently find the Longest Palindromic Substring.

  • Left, Right
  • Odd, Even
  • Palindrome, Non-palindrome
  • Prefix, Suffix
Manacher's Algorithm utilizes Odd and Even arrays to efficiently find the Longest Palindromic Substring. These arrays help to avoid unnecessary re-computation by taking advantage of the symmetric properties of palindromes.

Which pattern matching algorithm uses hashing to efficiently find the occurrence of a pattern within a text?

  • Boyer-Moore Algorithm
  • Brute Force Algorithm
  • Knuth-Morris-Pratt Algorithm
  • Rabin-Karp Algorithm
The Rabin-Karp Algorithm uses hashing to efficiently find the occurrence of a pattern within a text. It employs hash functions to create hash values for the pattern and substrings of the text, enabling faster pattern matching.

What is the time complexity of the brute-force approach for finding the Longest Palindromic Substring?

  • O(log n)
  • O(n log n)
  • O(n)
  • O(n^2)
The time complexity of the brute-force approach for finding the Longest Palindromic Substring is O(n^2), where 'n' is the length of the input string. This is because it involves nested loops to explore all possible substrings.

Quick Sort's _______ step divides the array into two subarrays.

  • Compare
  • Merge
  • Partition
  • Shuffle
Quick Sort's partition step divides the array into two subarrays. It chooses a pivot, rearranges the elements such that elements less than the pivot are on the left, and elements greater than the pivot are on the right. This step is pivotal for the algorithm.

The greedy behavior in regular expression matching tries to match as _______ characters as possible in a given input string.

  • Few
  • Fewest
  • Many
  • Most
The greedy behavior in regular expression matching tries to match as many characters as possible in a given input string. This means that the pattern will attempt to extend as far as it can within the constraints of the overall match.

Consider a scenario where you're tasked with developing a plagiarism detection system for a large database of academic papers. How would you approach using the longest common substring to efficiently identify potential instances of plagiarism?

  • By comparing the overall length of the papers without analyzing substrings.
  • By extracting the longest common substrings and comparing their frequencies across different papers.
  • By focusing on the title and abstract sections of the papers for substring comparison.
  • By using only the conclusion sections for substring matching.
In a plagiarism detection system, utilizing the longest common substrings involves extracting these substrings and comparing their frequencies across different papers. This helps efficiently identify potential instances of plagiarism by pinpointing similarities in content.

What is the objective of the coin change problem?

  • Achieving a combination of coins that sums up to a specific target value.
  • Maximizing the number of coins in a given set.
  • Minimizing the total weight of the coins.
  • Sorting coins in descending order based on their denominations.
The objective of the coin change problem is to find the minimum number of coins needed to make up a given target value. It involves determining the optimal combination of coins to minimize the total number of coins used.

Imagine you are implementing a compiler and need to store a symbol table efficiently. Would you prefer an AVL tree or a red-black tree for this purpose, and what factors would influence your decision?

  • AVL Tree
  • Both AVL and Red-Black Trees
  • Hash Table
  • Red-Black Tree
An AVL Tree would be preferred for storing a symbol table in a compiler. AVL Trees guarantee a stricter balance compared to Red-Black Trees, leading to faster search operations. The compiler's symbol table benefits from the AVL Tree's consistent logarithmic time complexity for search operations.