Difference between Inverted Index and Forward Index

Inverted Index and Forward Index are data structures used to search text within a document or a collection of documents. They differ in how they map the relationship between words and documents − one indexes by word, the other by document.

Forward Index

A forward index stores the document name as the key and maps it to the list of words contained in that document. It answers the question: "What words does this document contain?"

Inverted Index

An inverted index stores each word as the key and maps it to the list of documents that contain that word. It answers the question: "Which documents contain this word?" This is the index structure used by search engines.

Example

Consider three documents −

doc1: "Welcome Hello"
doc2: "Hi"
doc3: "Hello"

The forward and inverted indexes would be −

Forward Index Document → Words doc1 → Welcome, Hello doc2 → Hi doc3 → Hello Fast to build, slow to search Inverted Index Word → Documents Welcome → doc1 Hello → doc1, doc3 Hi → doc2 Slow to build, fast to search

Key Differences

Feature Inverted Index Forward Index
Mapping Word → Documents Document → Words
Index Building Slower (check for duplicate words) Faster (append words as found)
Searching Fast (direct word lookup) Slow (scan all documents)
Duplicate Keywords No duplicates in index Duplicates possible across documents
Real-Life Analogy Book glossary, search engine index Table of contents, DNS lookup

Conclusion

Forward indexes map documents to their words and are fast to build. Inverted indexes map words to their documents and are fast to search. Search engines like Google use inverted indexes because the primary operation is finding documents that match a search query.

Updated on: 2026-03-14T13:01:47+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements