O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An example – books with an index of words

Imagine we have three books: Book 1, Book 2, and Book 3, and the following are their respective indexes. The numbers beside each word represent which page the word occurs on:

* Book 1 (Index)
  - apple - 4, 10, 20
  - cat - 10, 21, 22
  - zebra - 15, 25, 63
    
* Book 2 (Index)
  - banana - 14, 19, 66
  - cake - 10, 37, 45
  - zebra - 67, 100, 129
    
* Book 3 (Index)
  - apple - 36, 55, 74
  - cake - 1, 9, 77
  - Whale - 11, 59, 79  

Let's try to find three words from the books' indexes. A naïve approach might be to pick each book and scan it until we hit or miss the word:

  • apple
  • banana
  • parrot
* Searching for 'apple'
  - Scanning Book 1. Result: Found.
  - Scanning Book 2. Result: Not Found.
 - Scanning Book 3. Result: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required