Artificial Intelligence & Data Science is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Boolean retrieval

Boolean retrieval is a binary (yes/no) model that uses Boolean logic on term occurrences to return documents; engineers use it for simple search, filters, and as a building block for inverted-index operations and query processing.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Boolean retrieval is the simplest practical retrieval model. An engineer uses it when building fast filters, access-control checks, faceted search, or the initial stage of query processing on an inverted index before any ranking (see "TF-IDF and the inverted index", "Query processing" and "Query optimisation and impact ordering"). It is easy to implement and explains core concepts like postings lists, set operations and query plan cost that appear across more advanced IR topics.

Key ideas

  • Posting / postings list — for a term t, the postings list is the list of document identifiers (docIDs) in which t occurs. Usually stored sorted by docID. The postings list is the concrete data structure on which Boolean operations operate.

  • Incidence vector — for term t, the incidence vector is a binary vector of length |U| where the i-th entry is 1 if document i contains t, else 0. Relation: incidence vectors are equivalent to sets of docIDs; set operations correspond to Boolean algebra on vectors.

  • Boolean operators (set semantics):

    • AND (conjunction): documents that contain both terms. If A and B are sets of docIDs, A AND B = A ∩ B.
    • OR (disjunction): documents that contain at least one term. A OR B = A ∪ B.
    • NOT (negation / complement): documents that do not contain a term, with respect to the corpus U. NOT A = U \ A.

    State the algebraic laws used in exam answers:

    • Commutativity: A ∪ B = B ∪ A and A ∩ B = B ∩ A.
    • Associativity: (A ∪ B) ∪ C = A ∪ (B ∪ C) and similarly for ∩.
    • Distributivity: A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) and A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
    • De Morgan's laws: U \ (A ∪ B) = (U \ A) ∩ (U \ B) and U \ (A ∩ B) = (U \ A) ∪ (U \ B).
    • Identity: A ∪ ∅ = A, A ∩ U = A.
    • Annihilator: A ∪ U = U, A ∩ ∅ = ∅.
    • Idempotent: A ∪ A = A, A ∩ A = A.
    • Absorption: A ∪ (A ∩ B) = A, A ∩ (A ∪ B) = A.
    • Complement and double negation: A ∪ (U \ A) = U, A ∩ (U \ A) = ∅, and U \ (U \ A) = A.
    • Precedence (for exam problems): NOT > AND > OR (AND/OR left-associative).
  • Query equivalence and normalization — Boolean expressions can be transformed to Conjunctive Normal Form (CNF) or Disjunctive Normal Form (DNF) using the laws above. CNF is a conjunction of disjunctions; DNF is a disjunction of conjunctions. Normal forms are used for query planning and optimisation.

  • Execution on inverted index — evaluate each atomic term by fetching its postings list, then combine lists using set-operations: intersection for AND, union for OR, and complement with respect to the full docID set for NOT. The typical algorithms rely on the postings lists being sorted. For A AND NOT B, implement as A \ B (set difference) to avoid materialising the complement; difference can be computed by a linear merge in O(|A| + |B|).

  • Cost model (assumptions) — simplest cost estimate counts memory accesses or comparisons. For merging two sorted postings lists of lengths n and m using the linear merge (two-pointer) algorithm, worst-case time is O(n + m). This assumes sequential scan over lists; skip pointers and compression affect constants but not asymptotic order here. Also track sizes: |A| = number of documents in A; |U| = total documents.

  • Limitations — Boolean retrieval gives only binary answers (no ranking), is brittle to term mismatch, and does not exploit term weights (contrast with TF-IDF, BM25). It also needs careful handling of NOT (complement) because complements can be very large.

  • Diagram to draw when asked in an exam: draw a rectangle labelled "U (corpus)". Inside draw two overlapping circles labelled A and B. Shade intersection for A AND B; shade both circles (the union) for A OR B; shade area outside A but inside U for NOT A. Label cardinalities |A|, |B|, |A ∩ B|.

Formulas

|A| = number of documents in set A

  • |A| meaning: cardinality (count) of set A; SI unit: count (documents); applies always.

|U| = total number of documents in the corpus

  • |U| meaning: size of universe; unit: count (documents).

A AND B = A ∩ B

  • meaning: set intersection; applies when query uses conjunction.

A OR B = A ∪ B

  • meaning: set union; applies for disjunction.

NOT A = U \ A = {d in U | d ∉ A}

  • meaning: complement with respect to corpus U; applies to negation.

|U \ A| = |U| - |A|

  • meaning: cardinality of complement; applies whenever A ⊆ U and both are finite (evaluate against a consistent snapshot).

Cost(intersect(A,B)) = O(|A| + |B|)

  • meaning: time using linear-merge two-pointer algorithm; units: comparisons or pointer steps; assumes both lists are sorted.

Cost(union(A,B)) = O(|A| + |B|)

  • meaning: merging sorted lists; units: steps.

Cost(complement(A)) = O(|U|) (naive)

  • meaning: if we materialise complement explicitly or scan all documents; in practice we compute complement by logical negation when combining with small lists (avoid materialisation).

Note: these are asymptotic costs. Practical systems use skip pointers, block-level skipping, and compressed postings to reduce constants and I/O.

Worked examples

Example 1 — Model long-answer: Evaluate query (t1 AND (t2 OR NOT t3)) using postings lists.

Question (model answer): Given corpus U = {1,2,3,4,5,6,7,8,9,10}. Postings:

  • t1: {1,2,5,8}
  • t2: {2,3,5,9}
  • t3: {4,5,10}

Step 1 — Compute NOT t3 = U \ t3 = {1,2,3,6,7,8,9} Step 2 — Compute t2 OR NOT t3 = {2,3,5,9} ∪ {1,2,3,6,7,8,9} = {1,2,3,5,6,7,8,9} Step 3 — Compute t1 AND result = {1,2,5,8} ∩ {1,2,3,5,6,7,8,9} = {1,2,5,8}

Final answer: {1,2,5,8}. Explain each set operation and that NOT used universe U of size 10.

Example 2 — Model long-answer: Convert Boolean expression to CNF and show why CNF helps.

Question (model answer): Convert expression (a OR (b AND c)) to CNF.

Step 1 — Use distributivity: a OR (b AND c) = (a OR b) AND (a OR c). Step 2 — This is now CNF: conjunction of clauses (a OR b) and (a OR c).

Explain: CNF is useful because a query planner can evaluate each disjunctive clause's postings and then intersect clause results; if a clause is small it quickly reduces candidate set.

Example 3 — Cost-aware ordering (short): Given postings sizes |a|=1000, |b|=50, |c|=10. Question: For query a AND b AND c, what order of intersections minimises cost?

Model answer: Intersect the smallest lists first. Intersect b (50) with c (10) cost O(60) producing at most 10 results; then intersect with a cost O(10 + 1000) ≈ O(1010). If you did a∩b first cost O(1050), then intersect result with c cost O(50 + 10) = O(60), for a total of about O(1110). So ordering by increasing posting size is best.

Common mistakes

  • Ignoring preprocessing: term mismatch (case, stemming) results in wrong postings fetched.
  • Assuming cost O(min(n,m)) for intersection; correct basic cost using two-pointer merge is O(n + m), though optimisations and skip pointers reduce practical cost.
  • Materialising large complements (NOT) instead of using algebraic transforms; this causes heavy work.
  • Forgetting to sort postings lists (required for linear-merge) or not using sorted docIDs when using two-pointer algorithms.

For your exam

Question types you will see: definitions (define Boolean retrieval, postings list, incidence vector), short notes (advantages/limitations), derivations/proofs (prove De Morgan, show equivalence transformations), diagram questions (draw Venn to illustrate AND/OR/NOT), algorithmic or pseudo-code (merge intersection), and cost numericals (compute steps for merges and choose best order), and long model answers like those above.

What a full-marks answer includes:

  • Precise definitions with bold terms (Boolean retrieval, postings list, incidence vector).
  • A clear statement of assumptions (binary relevance, sorted postings, universe U known).
  • Correct use of set algebra with stated laws (commutativity, distributivity, De Morgan) and step-by-step transformations for normal forms.
  • For algorithmic answers: write the two-pointer merge algorithm or describe steps, state complexity, and discuss optimisations (skip pointers, compression) briefly.
  • For cost questions: show list sizes, compute intermediate sizes, give final cost estimate with reasoning.

References to other topics: mention that Boolean retrieval operates on the inverted index (see "TF-IDF and the inverted index"), that preprocessing (tokenisation, stemming) affects terms, and that ranking models (vector space, BM25) extend Boolean by adding weights.

Quick check

  1. Define the postings list for a term t in one sentence.
  2. State De Morgan's law for sets in the form with union.
  3. For two postings lists of sizes 120 and 80, what is the asymptotic cost of their intersection using two-pointer merge?

Answers: 1) A postings list is the sorted list of docIDs of documents that contain term t. 2) U \ (A ∪ B) = (U \ A) ∩ (U \ B). 3) O(200).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?