ArticleslgStudy

computer science

Finger search

Finger search is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Finger search rather than just read about it. In short: In computer science, a finger search on a data structure is an extension of any search operation that structure supports, where a reference (finger) to an element in the data structure is given along with the query. While the search time for an element is most frequently expressed as a function of the number of elements in a data structure, finger search times are a function of the distance between the element and t…

Finger search — main illustration
Finger search — illustration

Key takeaways

  • Finger search belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Finger search to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Finger search from memory before moving on to harder problems.

Reference excerpt

In computer science, a finger search on a data structure is an extension of any search operation that structure supports, where a reference (finger) to an element in the data structure is given along with the query. While the search time for an element is most frequently expressed as a function of the number of elements in a data structure, finger search times are a function of the distance between the element and the finger. In a set of n elements, the distance d(x,y) (or simply d when unambiguous) between two elements x and y is their difference in rank. If x and y are the ith and jth largest elements in the structure, then the difference in rank is |i - j|. If a normal search in some structure would normally take ⁠O(f(n))⁠ time, then a finger search for x with finger y should ideally take ⁠O(f(d))⁠ time. Remark that since d ≤ n, it follows that in the worst case, finger search is only as bad as normal search. However, in practice these degenerate finger searches do more work than normal searches. For instance, if f(n) is log(n), and finger search does twice as many comparisons as normal search in the worst case, it follows that finger search is slower when d > √n. Therefore, finger search should only be used when one can reasonably expect the target to actually be close to the finger.

Implementations Some popular data structures support finger search with no additional changes to the actual structure. In structures where searching for an element x is accomplished by narrowing down an interval over which x can be found, finger search from y is typically accomplished by reversing the search process from y until the search interval is large enough to contain x, at which point search proceeds as normal.

Sorted linked lists In a linked list, one normally searches linearly for an element by walking from one end to the other. If the linked list is sorted, and we have a reference to some node containing y, then we may find x in O(d) time by starting our search from y.

Sorted arrays In a sorted array A, one normally searches for an element x in A with a binary search. Finger search is accomplished by performing a one-sided search from A[j] = y. While binary search halves the search space after each comparison, one-sided search doubles the search space after each comparison. Specifically, on the kth iteration of one-sided search (assuming ⁠x>y⁠), the interval under consideration is A[j, j+2k−1]. Expansion halts as soon as A[j + 2k−1] ≥ x, at which point this interval is binary searched for x. If one-sided search takes k iterations to find an interval that contains x, then it follows that d > 2k−2. Binary searching this range will also take another k iterations. Therefore, finger search for x from y takes O(k) = O(log d) time.

Skip lists In a skip list, one can finger search for x from a node containing the element y by simply continuing the search from this point. Note that if ⁠x<y⁠, then search proceeds backwards, and if ⁠x>y⁠, then search proceeds forwards. The backwards case is symmetric to normal search in a skip list, but the forward case is actually more complex. Normally, search in a skiplist is expected to be fast because the sentinel at the start of the list is as tall as the tallest node. However, our finger could be a node of height 1. Because of this, we may occasionally climb while trying to search; something which never occurs normally. However, even with this complication, we can achieve O(log d) expected search time.

Treaps A treap is a randomized binary search tree (BST). Searching in a treap is the same as searching for an element in any other BST. Treaps however have the property that the expected path length between two elements of distance d is O(log d). Thus, to finger search from the node containing y for x, one can climb the tree from y until an ancestor of x is found, at which point normal BST search proceeds as usual. While determining if a node is the ancestor of another is non-trivial, one may augment the tree to support queries of this form to give expected O(log d) finger search time.

Ropes and trees Implementations of the rope (data structure) typically implement a cord position iterator to traverse the string. The iterator can be seen as a finger that points at some specific character of the string. Like most balanced trees, ropes require O(log(n)) time to retrieve data in one leaf of the tree when given only the root of the tree. Reading every leaf of the tree would seem to require O(n·log(n)) time. However, by storing a little extra information, the iterator can be used to read "the next" leaf in only O(1) time, and every leaf of a tree in only O(n) time. Implementations of ropes typically cache "extra information" about the entire the path from the root to the current node position in the iterator. Other implementations of tree data structures sometimes store "extra information" in the tree itself, storing a pointer in each node to its parent or its successor (in addition to the normal pointers in each node to its children), and storing only the current node position in the iterator.

Generalizations If one can perform finger search in an iterative manner in O(f(d)) time, where each iteration takes O(1) time, then by providing c different fingers, one can perform finger search in O(c min{d(x, y1), ..., d(x, yc)}) time. This is accomplished by starting finger search for all c fingers, and iterating them forward one step each until the first one terminates. Given any sequence A = [a1, ..., am] of m accesses, a structure is said to have the static finger property for a fixed finger f, if the time to perform A is O(∑i=1mlog⁡d(f,ai)). Splay trees have this property for any choice of f with no additional processing on sufficiently large sequences of accesses.

… excerpt ends here. Continue reading the full article.

Illustrations

Finger search: Example of finger search on treaps.
Example of finger search on treaps.

Worked examples

Example 1 — a first encounter with Finger search

Start with the simplest possible case. Write down what Finger search claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Finger search before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Finger search ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Finger search

In research
Finger search appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Finger search in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Finger search is common in secondary-school and first-year university syllabi. It links to neighbouring topics Search algorithms, Trees (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for Finger search outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Finger search” →

How to study Finger search in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Finger search means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Finger search out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Finger search in simple terms?

In computer science, a finger search on a data structure is an extension of any search operation that structure supports, where a reference (finger) to an element in the data structure is given along with the query. While the search time for an element is most frequently expressed as a function of…

Why does Finger search matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Finger search?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Finger search.

Tags

  • Search algorithms
  • Trees (data structures)

Keep exploring