Data Structures & AlgorithmsModerateICPC regional · number theory
Problem: What is the time complexity of finding all prime factors of n up to 10^12 by trial division?
- A. O(log n)
- B. O(n)
- C. O(sqrt n)
- D. O(n log n)
Correct answer: C. O(sqrt n)
Trial division up to sqrt(n) takes about 10^6 steps for n = 10^12.
More Coding Interview Problems questions
- Problem: Which problem is solved by the 'meet in the middle' technique on a subset-sum instance with n = 40?
- Problem: What does the 'two-phase' Kosaraju algorithm compute?
- Problem: Which best describes the complexity of Dijkstra on a graph with V = 10^5 and E = 10^6 using an array instead of a heap?
- Problem: What is the Stern-Brocot tree's relevance to competitive programming?
- Problem: Which algorithm finds all integer points on the convex hull boundary of a set of points?
- Problem: What is the purpose of the 'sqrt decomposition' technique for an array?