This question evaluates numerical methods and algorithmic robustness, testing understanding of Newton’s method for root-finding, floating‑point stability and IEEE‑754 edge cases, and integer binary-search techniques for exact floor square roots within the Coding & Algorithms domain for a Data Scientist role.
Implement a Python function that returns the principal square root of a nonnegative float x without using sqrt or pow.
Requirements:
Implement a Python function that returns ⌊√n⌋ for an integer n with 0 ≤ n < 2^63 using binary search.
Requirements:
Answer the following:
a) Prove Newton’s method for √x is quadratically convergent near the root.
b) For worst-case x in [1e−12, 1e12] with starting guess y0 = max(1, x), estimate the number of iterations needed to reach tol = 1e−12 (per the stop rule) and justify.
c) Compare per-iteration cost and total operations of Newton’s method versus binary search for 64-bit n.
d) Briefly outline how to extend sqrt_newton to support complex results for x < 0 under IEEE‑754 and why naïve branching can be unsafe.
Login required