Skip to content

Leaps And Bounds Algorithm

  • A hybrid search that alternates between coarse linear scans and binary refinement to narrow a target’s location.
  • Useful for reducing the number of inspected elements when locating a value in a large sorted dataset.
  • Typical procedure: linear scan for a rough bracket, binary search to refine that bracket, then linear scan to find the exact element.

The Leaps-and-Bounds algorithm is a search method that uses a combination of linear and binary search techniques to efficiently find a target value within a sorted array.

The algorithm proceeds in stages using both linear and binary search methods from the source description:

  • Start with a linear search to obtain a rough estimate or bracket of where the target value lies within the sorted array.
  • Apply a binary search within that bracket to refine the estimate and narrow the search interval.
  • Finish with a linear search over the refined interval to locate the exact position of the target.

Combining these steps can significantly reduce the number of steps required to find a target value in a large dataset compared to scanning every element.

Suppose we have the sorted array: [1, 2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 18, 19, 20] We want to search for the value 8.

  • Use a linear search to determine 8 is likely between 7 and 11.
  • Use a binary search to refine the location to between 7 and 9.
  • Use a linear search within that refined range to locate 8.

Suppose a large text document contains many words and we want to find the word “apple”.

  • Use a linear search over an initial portion (for example, the first few hundred words) to get a rough estimate of the word’s location, such as words starting with “a”.
  • Use a binary search by dividing the document to refine which half contains “apple”.
  • Use a linear search within the refined search space to find the exact occurrence of “apple”.
  • Locating a target value within a large sorted dataset.
  • Searching for a specific word within a large text document.
  • Linear search
  • Binary search