Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between Inverted Index and Forward Index

  • Difficulty Level : Medium
  • Last Updated : 04 Jun, 2018

Inverted Index

  1. It is a data structure that stores mapping from words to documents or set of documents i.e. directs you from word to document.
  2. Steps to build Inverted index are:
    • Fetch the document and gather all the words.
    • Check for each word, if it is present then add reference of document to index else create new entry in index for that word.
    • Repeat above steps for all documents and sort the words.
  3. Indexing is slow as it first checks that word is present or not.
  4. Searching is very fast.
  5. Example of Inverted index:
    Word                              Documents
    hello                             doc1      
    sky                               doc1, doc3
    coffee                            doc2
    hi                                doc2
    greetings                         doc3                               

    It does not store duplicate keywords in index.

  6. Real life examples of Inverted index:
    • Index at the back of the book.
    • Reverse lookup

Forward Index:

  1. It is a data structure that stores mapping from documents to words i.e. directs you from document to word.
  2. Steps to build Forward index are:
    • Fetch the document and gather all the keywords.
    • Append all the keywords in the index entry for this document.
    • Repeat above steps for all documents
  3. Indexing is quite fast as it only append keywords as it move forwards.
  4. Searching is quite difficult as it has to look at every contents of index just to retrieve all pages related to word.
  5. Example of forward index:
    Document                          Keywords
    doc1                              hello, sky, morning      
    doc2                              tea, coffee, hi
    doc3                              greetings, sky

    It stores duplicate keywords in index. Eg: word “sky” is stored multiple times.

  6. Real life examples of Forward index:
    • Table of contents in book.
    • DNS lookup

Similarity between Forward index and Inverted Index:

  • Both are used to search text in document or set of documents.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!