Skip to content(if available)orjump to list(if available)

Sublinear Time Algorithms

Sublinear Time Algorithms

75 comments

·February 23, 2025

dataflow

> There are problems for which deterministic exact sublinear time algorithms are known.

I can imagine silly examples (like "find the minimum element in this list under the assumption that no more than O(sqrt(n)) elements exceed the minimum"...), but what's an interesting example of this?

_jab

Binary search is the obvious example.

What it and your example have in common is that a significant constraint exists on the input. I can't imagine how a deterministic algorithm with unconstrained input can process that input in sublinear time, but I would love to learn otherwise.

dataflow

I can't imagine that's what they meant? The text very specifically says: "Indeed, it is hard to imagine doing much better than that, since for any nontrivial problem, it would seem that an algorithm must consider all of the input in order to make a decision." For them to be thinking of binary search, they would have to be effectively saying "it is hard to think of binary search", which would be a rather absurd position from a CS professor, especially given binary search is quite literally the first algorithm every programmer learns.

So I took it to mean there's something interesting here where the inputs could literally be anything, not heavily constrained. But I can't imagine what that might be.

kadoban

> especially given binary search is quite literally the first algorithm every programmer learns.

I get what you're saying, and it doesn't change your point, but: no _way_ is binary search the first algorithm people learn. For binary search to even be intelligible you already have to know, at a minumum linear search and the concept of sorting (you probably know a sorting algorithm first). You also learn dozens of other really simple algorithms first in practice.

FreakLegion

They say a little ways down:

> there are classical optimization problems whose values can be approximated in sublinear time

This can actually be quite useful if the approximation is guaranteed, or even if it isn't, as long as it works well in practice.

https://en.wikipedia.org/wiki/Hardness_of_approximation

lqet

Here a a few examples, linked in the article:

https://www.dcs.warwick.ac.uk/~czumaj/PUBLICATIONS/DRAFTS/Dr...

Searching in sorted lists is the first example, although they acknowledge that "the assumption that the input array is sorted is not natural in typical applications." They then give an non-trivial variant of this problem, where the sorted list is stored as a linked list, so that you cannot directly jump to some element at position i.

Another example for a sublinear algorithm they give is to check whether 2 convex polygons intersect, using the algorithm by Chazelle and Dobkin.

null

[deleted]

HelloNurse

It is obvious that binary search leverages the property that the input is sorted in order to ignore part of the input, but it is less obvious to see it abstractly as an exotic specimen of sublinear exact algorithm rather than merely as a simple special case of search, and it is even less obvious to investigate what weaker (and hopefully cheaper to guarantee) input constraints allow sublinear search algorithms.

dzaima

I read that as saying that binary search isn't among those "nontrivial problem"s, along with most other things with known exact deterministic sublinear time algorithms.

And your first quote is followed by "However, for most natural problems", which further indicates that the known exact algorithms are for trivial problems.

Aurornis

Binary search requires a sorted input, which requires that you first consider all elements of the input data set.

The sublinear algorithms this page is discussing require that the algorithm not consider all elements of the data set and you're not allowed to pre-process it with an O(n) or greater algorithm.

So no trees, no binary search. It's a different set of algorithms.

karparov

Another obvious example: What's the mean of an unsorted list of integers? If you do a random sample of sqrt(n) values and mean over that, you guess is with high probability pretty good. Or a log(n) sample. (That's how election polling works too which uses even a O(1) sample though not random.)

Edit: Ah, GP asked for deterministic exact.

null

[deleted]

amelius

What if one if the integers is significantly larger than the rest?

spoaceman7777

I mean, yeah, binary search is sublinear, but the data has to be ordered into a binary search tree to be able to use it, which has a much more familiar (non-sub-linear) runtime.

I have to assume the reason for the article wasn't to talk about the runtime of algorithms that operate on data that's already in a partially solved state.

JonChesterfield

Data structured as trees permit a lot of sublinear operations. Set intersection for example, you traverse the two trees in the same order, and where a node exists in one and not the other, you know nothing under it is in the intersection.

Aurornis

In this case, Sublinear Algorithms refers to algorithms that don't consider the entire input set.

A B-Tree would not qualify because it must first consider the entire input set. Only later operations can be less than O(n) because you've already done O(n) or greater work on the data set.

ssivark

Think from an information theory perspective. It is rarely true that you cannot say anything more about the data than what is assumed by classical algorithms. We almost always have some more information depending on the specific domain under consideration. Eg: Sorting a list of ages might be very different from sorting a list of account balances.

Any time I have information that reduces the entropy of the dataset, I want to be able to leverage that into runtime improvements of algorithms for pertinent questions. And it would be great to develop a structured framework for that instead of handling special cases in an ad-hoc manner.

ssivark

As one example of such a more general framework -- (variants of) belief propagation might be a good answer if dataset constraints could be cleanly formulated as distributions to be reasoned with.

oxavier

My work is about inferring solutions to Constraint Satisfaction Problem by using belief propagation in the corresponding constraint network, a few keywords caught my eye here :)

Do you have any illustrative example so I can understand better what you are hinting at?

Cheers

minutillo

dataflow

Isn't that O(mn) worst-case run time?

quuxplusone

No, it's O(n) worst case. (The Wikipedia sidebar says "O(mn)," but that's apparently for a maimed version of the algorithm without a key part they're calling "the Galil rule." That's a special usage of the phrase "worst case"! In the absolute worst case, your implementation could have a bug and never terminate at all!)

Anyway, the point is that it's O(n/m) in the usual case. Which remains technically linear, not sub-linear; but at least it's O(n) with a constant factor smaller than 1.

an_ko

Fully dynamic connectivity on general graphs comes to mind. https://en.m.wikipedia.org/wiki/Dynamic_connectivity (Graphs, with operations to connect and disconnect nodes, and to check whether two nodes are connected by some path.)

State of the art there is poly-logarithmic time worst case.

gleenn

Anything probabilistic? There are so many interesting fields where you can assume the distribution of a dataset and the take a sample of data and assert things about it with a high degree of confidence. All of modern AI is built on so much of this. All the Deep Neural Nets are making grand assumptions about the shape of meaning of data, they literally assume convexity of the space and they have clearly very interesting results despite the imprecision of the model. Anything dealing with finance is also dealing in lack of data. So if you had a list of prices of a stock over time, you could probably start making assumptions exactly like that, tgat the probability that it doubles over a short time is so unlikely so you can subsample the data and have it still be super useful to make assumptions exactly, especially when you have intractably large data.

dataflow

>> deterministic exact

> Anything probabilistic?

Are you sure you're answering the same question I'm asking?

latency-guy2

I wouldn't call that example silly IMO.

I'd consider all the varieties of B-Tree to be real example, which goes to any DBMS. You can extend this out to any direction you want like logging for concrete examples.

GIS/Mapping/computer vision has tons of algorithms and data structures that all needed to do better than linear time as well.

Stream processing in general is another, but that ends up being probabilistic more often than not, so weak punt into that direction.

If you expand the use case out to sublinear space as well, I'd argue for compression of all kinds.

qyph

https://en.wikipedia.org/wiki/AKS_primality_test though it's number theory, and concerned with numbers of size n, rather than lists of length n.

Also relevant: https://www.cs.yale.edu/homes/aspnes/pinewiki/Derandomizatio...

Ar-Curunir

AKS is not sublinear. It runs in poly(n) time, where n is the number of bits in the input (i.e. input size).

dataflow

> https://en.wikipedia.org/wiki/AKS_primality_test though it's number theory, and concerned with numbers of size n, rather than lists of length n.

They were talking about not reading a lot of the input, so that's not it.

alok-g

For that case, a better 'n' to use could be the number of digits in the number.

shae

This sounds like a useful way to mix in statistics and get useful approximations. I'm reading one of the survey links and it's approximately eye opening.

dooglius

Often for problems taking integer input x, formal CS will define the input to be something like 1^x (the character '1' repeated x times, as opposed to binary) so that the time complexity is in terms of x. This class of problems seems amenable to sublinear time since only only needs log(x) steps to determine x.

LPisGood

Actually if you try to formally define sublinear time algorithms in this manner they all collapse to constant time algorithms.

To see why, realize that to determine x, the TM needs to look at x many bits. If this algorithm only needed, say, log(x) many bits to produce output then all input values with more than log(x) bits are indistinguishable by this TM.

tromp

The notion of sublinear time only makes sense with Random-access Machines [1], not with Turing Machines.

[1] https://en.wikipedia.org/wiki/Random-access_machine

dooglius

Pretty much any standard notion of time complexity requires one to assume a random access machine, or else e.g. an array access is O(index) time.

doormatt

So like HyperLogLog?

qyph

Hyperloglog analyses generally assume access to the full data stream, and so are O(n) at a minimum. Perhaps by running hyperloglog on a sublinear sample of the dataset you'd get an algorithm in this class.

doormatt

That makes sense, thanks for explaining!

dataflow

HyperLogLog uses sublinear space, not sublinear time.