Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4048102
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:46:30+00:00 2026-05-20T13:46:30+00:00

Gallop search is for searching for an element in a sorted list. You start

  • 0

Gallop search is for searching for an element in a sorted list. You start taking an element at index 0, then at index 1, 2, 4, 8, 16, etc. until you overshoot your target, then you search again in the range that you just found.

What’s the time complexity of this? It seems to me to be some sort of logarithmic time complexity, but I can’t figure out what.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:46:31+00:00Added an answer on May 20, 2026 at 1:46 pm

    (Please see my EDIT below)

    lets look at the worst-case behaviour. search continues from 0, 1, 2, 4, 8….
    lets say n is 2^k for some k >= 0. in the worst-case we might end up searching until 2^k and realise we overshot the target. Now we know that target can be in 2^(k – 1) and 2^k. The number of elements in that range are 2^(k – 1) (think a second.). The number of elements that we have examined so far is O(k) which is O(logn). The following recurrence summarises it.

    T(n) = T(n/2) + O(logn) 
         = T(n/4) + c1log(n/2) + c2logn ((all logs are base 2.))
         .
         .
         .
         .
         = O((logn)^2)
    

    So the worst-case complexity of this algorithm is quadratic of logn. It maybe not the tightest bound but it is a good upper bound.

    EDIT: I’m mistaken. I have taken the definition of gallop search given here literally without following the link. The link says, once we overshoot, we do binary search in the previous interval. It takes log(n) time to overshoot the target and log(n) time to do binary search in the sorted interval. This makes it O(log(n)) algorithm. Thanks to Sumudu Fernando for pointing it out in the comments. I appreciate it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a page that will scan a site and then extract certain
Hey so im trying to get the current oil price and then do some
Trying to figure out why my list() class pointers are being overwritten with the
In FleetTUI.java I have a list of Fleets (Each fleet will hold its own
I have my mysql query selected fields (item_code, item_name, item quantity, item_selltype, item_selldetail) but
I'm in a programming class where we have just switched from python to C.
I'm using the plotmatrix function in ggplot2 (ggplot2_0.8.8) and would like to override the
I have an EXCEL sheet.it has various form-fields that are named as smrBgm133GallonsGross/ smrBgm167GallonsGross
Possible Duplicate: What is the difference between const and readonly? So from what I
I have a table with variable-width cells, and I want to give the browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.