Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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 −
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.
