Exponential Search

  • Exponential Search, like Binary Search is used to find an element from a sorted list. Other names of this type of search are doubling search or galloping search or Struzik search. Exponential Search works in two parts. First part finds a range within the list, which could have the searched item. Second part performs a Binary Search within the range to check for the searched item.

    Exponential Search has better performance than Linear Search. This can also perform better than Binary Search, when the element being searched are closer to the start of the array. This is because, the range is shorter at the beginning and also because the first part of the search, finishes execution in less iterations.

    If searched items are near the end of the list, performance is lesser than Binary Search.

    Time complexity of Exponential Search for average and worst cases are represented as O(log i), i being the index of the searched item. Space complexity is O(1).

    Practical use cases of Exponential Search are limited as Binary Search perform better in most of the scenarios.

  • How Exponential Search Works

    Exponential Search is also a divide and conquer method. Exponential search works in two parts similar to Jump Search.

    First section identifies a range within the array. If the searched item is present in the array, it will be within this range only. This is done by comparing the search key and the last element of each range.

    Once the range is identified, a Binary Search is performed on this range to check if the item is present.

    In the basic form of Exponential Search, start and end of the range are identified as the power of 2. For example;

    • Range 1 : Start = 0, End = 1
    • Range 2 : Start = 21 = 2, End = 22 = 4
    • Range 3 : Start = 22 = 4, End = 23 = 8
    • Range 4 : Start = 23 = 8, End = 24 = 16
    • Range 5 : Start = 24 = 16, End = 25 = 32

    Check the below gif image to easily understand the search process.

    Exponential Search
  • Algorithm

    Exponential Search Algorithm flow is listed as below.

    Input : A sorted list of elements.
    Output : Element position, if found. Else not found message.

    1. Start.
    2. Set start = 0, end = 1, pos = -1.
      start and end values represents the first range.
    3. Check if the searched item can be present within this range using formula arry[end] <= searched item
    4. If True, range identified. Exit loop. Go to step 6.
    5. If False, find next range. Start = Previous end, End = Start * 2. Go to step 3.
    6. Perform Binary Search on the identified range and check for the element and return the pos.
    7. If pos > -1, element found. Display result.
    8. Else if pos = -1, element not found. Display not found message.
    9. Stop.
  • Code Samples

    Below are few sample code implementations of Exponential Search Algorithm in Python, Java, C# and JavaScript.

Absolute Code Works - Python Topics