# Difference between Inverted Index and Forward Index

Inverted Index and Forward Index are data structures used to search text in a document or set of documents.

## Inverted Index

Inverted Index stores the words as index and document name(s) as mapped reference(s).

## Forward Index

Forward Index stores the document name as index and word(s) as mapped reference(s).

The following are some of the important differences between the Inverted Index and Forward Index.

Sr. No.KeyInverted IndexForward Index
1Mapping PatternInverted Index stores the words as index and document name(s) as mapped reference(s).Forward Index stores the document name as index and word(s) as mapped reference(s).
2Index Building Process
• Scan the document, prepare a list of unique words.

• Prepare a list of indexes of all unique words and map them to document search.

• Repeat the above steps for all the documents.

• Scan the document, prepare list of unique words.

• Map all the words to document as an index.

• Repeat the above steps for all the documents.

3IndexingIn the Inverted index, indexing is slow as each word has to be checked before preparing the index.In the forward index, indexing is fast as keywords are appended when found.
4SearchingIn the Inverted index, the search is quite fast.In the forward index, the search is slow.
5Example
Word Documents
-------------------------
Welcome doc1
Hello doc1, doc3
Hi doc2
-------------------------
Word Documents
-------------------------
doc1 Welcome, Hello
doc2 Hi
doc3 Hello
-------------------------
6DuplicityIn the Inverted index, no duplicate keyword is stored in an index.In the forward index, duplicate keywords can be present in an index like 'Hello'.
7Real-Life ExamplesA glossary at end of the index, Reverse Lookup.Table of Content at the start of the book, DNS lookup.