Embercode
✕
Segment TreesQuick quiz

Compression and merge sort trees

8 questions. Covers Merge sort tree for range order queries in Python.

Questions 1 to 5 of 8

  1. 1. Predict the output of this program. ``python from bisect import bisect_left, bisect_right values = [40, 10, 40, 1000] sorted_values = sorted(set(values)) print(sorted_values) print(bisect_left(sorted_values, 40)) print(bisect_left(sorted_values, 20)) print(bisect_left(sorted_values, 20), bisect_right(sorted_values, 40) - 1) print(bisect_left(sorted_values, 2000)) ``
  2. 2. Predict the output of this program. ``python def merge(x, y): out = [] i = j = 0 while i < len(x) and j < len(y): if x[i] <= y[j]: out.append(x[i]) i += 1 else: out.append(y[j]) j += 1 out.extend(x[i:]) out.extend(y[j:]) return out a = merge([2, 5], [6, 8]) b = merge([1, 7, 9], [3]) print(a) print(b) print(len(b)) ``
  3. 3. The sorted list is [5, 42, 900, 1000000000]. Which index does bisect_left(sorted, 6) return?
  4. 4. Why can a merge sort tree count the values below 40 in a range, when a sum tree cannot?
  5. 5. Which statements about the coordinate compression and merge sort tree lessons are true? Pick all that apply.

    Pick every answer that is true.

5 question(s) left on this page.