Galloping/Exponential Search, Document-Oriented Indexes




CS267

Chris Pollett

Feb 17, 2021

Outline

Introduction

Generating all Occurrences.

Implementing our ADT.

More on Implementing next and prev

Galloping Search (aka Exponential Search)

Using Galloping Search to Implement Next and Prev. (Bentley-Yao 1976)

function next(t, current)
{
   // P[][] = array of posting list arrays
   // l[] = array of lengths of these posting lists
   static c = []; //last index positions for terms 

   if(l[t] == 0 || P[t][l[t]] <= current) then
       return infty;
   if( P[t][1] > current) then
       c[t] := 1;
       return P[t][c[t]];

   if( c[t] > 1 && P[t][c[t] - 1] <= current ) do
      low := c[t] -1;
   else
      low := 1;

   jump := 1;

   high := low + jump;

   while (high < l[t] && P[t][high] <= current) do
      low := high;
      jump := 2*jump;
      high := low + jump;
   if(high > l[t]) then
      high := l[t];
   c[t] = binarySearch(t, low, high, current)
   return P[t][c[t]];
}

The book gives a nice analysis of the runtime returning all exact phrase matches when using this algorithm and shows it to be: `O(n cdot l cdot (log (L/l) + 1))`

In-Class Exercise

Documents and Other Elements

Document-oriented Indexes