Data Structures & AlgorithmsHardICPC regional · MST round
Problem: Consider a connected undirected graph whose edge weights are all distinct. Which statement is true?
- A. Kruskal's algorithm can produce a different MST than Prim's
- B. The MST is unique only when the graph is a tree
- C. Negative weights are required for uniqueness
- D. Its minimum spanning tree is unique
Correct answer: D. Its minimum spanning tree is unique
If all weights are distinct, the lightest edge across every cut is unique, so the MST is unique. Ties are what allow several minimum spanning trees.
More Coding Interview Problems questions
- Problem: What is the standard time complexity of bitmask DP for the travelling salesman problem on n cities?
- Array a = [3, -1, 2, 6, -4, 5, 1, -2]. How many non-empty contiguous subarrays have a sum divisible by 4?
- Binary array a = [1, 0, 1, 1, 0, 0, 1, 0, 1]. How many contiguous subarrays have exactly two 1s?
- Array a = [4, 2, 7, 1, 8, 3, 6, 5]. What is the largest sum of a contiguous subarray whose length is between 2 and 4 inclusive?
- In the string "abcabcaab", count the non-empty substrings that contain equally many vowels and consonants (vowels are a, e, i, o, u).
- For the array a = [1, 4, 7, 2, 5, 6, 3], how many index pairs i < j satisfy a[i] XOR a[j] = 5?