Embercode
✕
GraphsQuick quiz

Union-find

8 questions. Covers Accounts merge with union-find on strings in Python.

Questions 1 to 5 of 8

  1. 1. A union-find forest uses union by size. The counting argument says a tree with depth d holds at least 2^d elements. With 100,000 elements, what is the largest depth any element can have?
  2. 2. Which statements about path halving in find are true?

    Pick every answer that is true.

  3. 3. What does this program print? ``python parent = [1, 2, 3, 4, 5, 5] def find(x): while parent[x] != x: parent[x] = parent[parent[x]] x = parent[x] return x print(find(1)) print(parent) ``
  4. 4. Which statement about this union is correct? ``python def union(a, b): parent[a] = b ` Here a and b are element numbers and parent` is the list from the lesson.
  5. 5. What does this program print? ``python uf = UnionFind(5) uf.union(0, 1) uf.union(2, 3) uf.union(0, 2) print(uf.find(3) == uf.find(1), uf.find(1) == uf.find(4), uf.find(4)) ` Use the UnionFind` class from the accounts-merge program in this lesson.

5 question(s) left on this page.