Embercode
✕
Divide and ConquerQuick quiz

Median and matrices in Python

8 questions. Covers Matrix multiplication cost in Python.

Questions 1 to 5 of 8

  1. 1. The find_median search for two sorted lists of m and n values, as written in the lesson, runs in which time?
  2. 2. The lesson's Strassen recurrence is T(n) = 7 T(n/2) + n squared. Which growth rate does it give?
  3. 3. What does this program print? ``python a = [2, 4, 6] b = [1, 3, 5, 7] m = len(a) n = len(b) half = (m + n + 1) // 2 i = 1 j = half - i print(f'half={half} i={i} j={j} aLeft={a[i - 1]} bRight={b[j]}') c = [1, 2, 3, 4] d = [5, 6, 7, 8, 9] print(f'half={(len(c) + len(d) + 1) // 2} total={len(c) + len(d)}') ``
  4. 4. What does this program print? ``python def naive(a, b): n = len(a) c = [[0] * n for _ in range(n)] for i in range(n): for k in range(n): for j in range(n): c[i][j] += a[i][k] * b[k][j] return c a = [[1, 0], [2, 1]] b = [[3, 1], [0, 2]] print(naive(a, b)) x = [[2, 1], [0, 3]] y = [[1, 4], [2, 5]] print(naive(x, y)) ``
  5. 5. Why does find_median compute half as (m + n + 1) // 2 instead of (m + n) // 2?

5 question(s) left on this page.