Data Structures & AlgorithmsModerateICPC regional · graph theory
Problem: An undirected connected graph has an Euler circuit (a closed walk using every edge exactly once) if and only if which condition holds?
- A. Exactly two vertices have odd degree
- B. Every vertex has odd degree
- C. Every vertex has even degree
- D. The graph is a tree
Correct answer: C. Every vertex has even degree
Euler's theorem: a connected graph has an Euler circuit exactly when all degrees are even, and an Euler path (not circuit) needs exactly two odd vertices. Two odd vertices is the trap for the path condition.
More Coding Interview Problems questions
- Problem: Using 2D prefix sums on M = [[1,2,3],[4,5,6],[7,8,9]], what is the sum of the rectangle with rows 1..2 and columns 1..2…
- Problem: How many pairs (i < j) of a = [1, 2, 3, 4, 5, 6, 7] have a[i] + a[j] divisible by 4? python a = [1, 2, 3, 4, 5, 6, 7] print(sum(1…
- Problem: Count the subarrays of a = [10, 5, 2, 6] whose product is strictly less than k = 100. python def cnt(a, k): if k <= 1: return 0 p…
- Problem: How many distinct subsequences (including the empty one) does 'aba' have? Run the DP below. python def dsub(s): dp = [1] last =…
- Problem: The minimum number of insertions to make 'abcab' a palindrome equals n minus the length of its longest palindromic subsequence…
- Problem: Count pairs (i < j) of a = [1, 2, 3] with a[i] XOR a[j] summed over all pairs. What is the total of the XOR values? Run the code…