function build_inverted_index(documents):
   index = {}

   for doc_id, text in documents:
      for word in tokenize(text):
        index.setdefault(word, set()).add(doc_id)
   return index  # index["algorithm"] -> {doc_3, doc_17, doc_42}
