code: def bintree(ids, parent=None):
      """construct {child:parent} dict representation of a binary tree
  
      keys are the nodes in the tree, and values are the parent of each node.
  
      The root node has parent `parent`, default: None.
  
      >>> tree = bintree(range(7))
      >>> tree
      {0: None, 1: 0, 2: 1, 3: 1, 4: 0, 5: 4, 6: 4}
      >>> print_bintree(tree)
      0
        1
          2
          3
        4
          5
          6
      """
      parents = {}
      n = len(ids)
      if n == 0:
          return parents
      root = ids[0]
      parents[root] = parent
      if len(ids) == 1:
          return parents
      else:
          ids = ids[1:]
          n = len(ids)
          left = bintree(ids[: n // 2], parent=root)
          right = bintree(ids[n // 2 :], parent=root)
          parents.update(left)
          parents.update(right)
      return parents
  
imports: import re
  import socket
  from functools import reduce
  import zmq
  from ipyparallel.serialize import deserialize_object, serialize_object
  from ipyparallel.util import disambiguate_url
label_desc: Use image node_id 1 for calling a global function with example usage: bintree(ids, parent) and returns: parents, parents, parents