ArticleslgStudy

computer science

BK-tree

BK-tree 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 BK-tree rather than just read about it. In short: A BK-tree (short for Burkhard-Keller tree) is a metric tree suggested by Walter Austin Burkhard and Robert M. Keller[1] specifically adapted to discrete metric spaces.

BK-tree — main illustration
BK-tree — illustration

Key takeaways

  • BK-tree 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 BK-tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of BK-tree from memory before moving on to harder problems.

Reference excerpt

A BK-tree (short for Burkhard-Keller tree) is a metric tree suggested by Walter Austin Burkhard and Robert M. Keller[1] specifically adapted to discrete metric spaces. For simplicity, given a way to measure the distance between any two elements of a set, a BK-tree is built with a single root node and several subtrees, each connected to the root as a child. All nodes in a subtree have an equal distance to the root node, and the edge weight of the edge connecting the subtree to the root is equal to the distance. As shown in the picture. Also, each subtree of a BK-tree is a BK-tree.

BK-trees can be used for approximate string matching in a dictionary [2]. The problem is formulated as follows: Given a pattern string P=p1p2...pm and a text string T=t1t2…tn, we need to find a substring Tj′,j=tj′…tj in T, which, of all substrings of T, has the smallest edit distance to the pattern P. An ordinary way using BK-tree is to insert all Θ(n2) substrings of T and the pattern string P into the BK-tree, and find the subtree containing nodes with the smallest distance from the root. This will lead to a time complexity of Θ(n2log⁡n). However, this algorithm is very accurate and can find every substrings with the smallest edit distance to P.

Example

This picture depicts the BK-tree for the set W of words {"book", "books", "cake", "boo", "boon", "cook", "cape", "cart"} obtained by using the Levenshtein distance

each node u is labeled by a string of wu∈W; each arc (u,v) is labeled by duv=d(wu,wv) where wu denotes the word assigned to u. The BK-tree is built so that:

for all node u of the BK-tree, the weight assigned to its egress arcs are distinct; for all arc e=(u,v) labeled by k, each descendant v′ of v satisfies the following equation: d(wu,wv′)=k: Example 1: Consider the arc from "book" to "books". The distance between "book" and any word in {"books", "boo", "boon", "cook"} is equal to 1; Example 2: Consider the arc from "books" to "boo". The distance between "books" and any word in {"boo", "boon", "cook"} is equal to 2.

Insertion The insertion primitive is used to populate a BK-tree t according to a discrete metric d. Input:

t: the BK-tree; duv denotes the weight assigned to an arc (u,v); wu denotes word assigned to a node u; d: the discrete metric used by t (e.g. the Levenshtein distance); w: the element to be inserted into t; Output:

The node of t corresponding to w Algorithm:

If the t is empty: Create a root node r in t wr←w Return r Set u to the root of t While u exists: k←d(wu,w) If k=0: Return u Find v the child of u such that duv=k If v is not found: Create the node v wv←w Create the arc (u,v) duv←k Return v u←v

Lookup Given a searched element w, the lookup primitive traverses the BK-tree to find the closest element of w. The key idea is to restrict the exploration of t to nodes that can only improve the best candidate found so far by taking advantage of the BK-tree organization and of the triangle inequality (cut-off criterion). Input:

t: the BK-tree; d: the corresponding discrete metric (e.g. the Levenshtein distance); w: the searched element; dmax: the maximum distance allowed between the best match and w, defaults to +∞; Output:

wbest: the closest element to w stored in t and according to d or ⊥ if not found; Algorithm:

If t is empty: Return ⊥ Create S a set of nodes to process, and insert the root of t into S. (wbest,dbest)←(⊥,dmax) While S≠∅︀: Pop an arbitrary node u from S du←d(w,wu) If du<dbest: (wbest,dbest)←(wu,du) For each egress-arc (u,v): If |duv−du|<dbest: (cut-off criterion) Insert v into S. Return wbest

Example of the lookup algorithm Consider the example 8-node B-K Tree shown above and set w="cool". S is initialized to contain the root of the tree, which is subsequently popped as the first value of u with wu="book". Further du=2 since the distance from "book" to "cool" is 2, and dbest=2 as this is the best (i.e. smallest) distance found thus far. Next each outgoing arc from the root is considered in turn: the arc from "book" to "books" has weight 1, and since |1−2|=1 is less than dbest=2, the node containing "books" is inserted into S for further processing. The next arc, from "book" to "cake," has weight 4, and since |4−2|=2 is not less than dbest=2, the node containing "cake" is not inserted into S. Therefore, the subtree rooted at "cake" will be pruned from the search, as the word closest to "cool" cannot appear in that subtree. To see why this pruning is correct, notice that a candidate word c appearing in "cake"s subtree having distance less than 2 to "cool" would violate the triangle inequality: the triangle inequality requires that for this set of three numbers (as sides of a triangle), no two can sum to less than the third, but here the distance from "cool" to "book" (which is 2) plus the distance from "cool" to c (which is less than 2) cannot reach or exceed the distance from "book" to "cake" (which is 4). Therefore, it is safe to disregard the entire subtree rooted at "cake". Next the node containing "books" is popped from S and now du=3, the distance from "cool" to "books." As du>dbest, dbest remains set at 2 and the single outgoing arc from the node containing "books" is considered. Next, the node containing "boo" is popped from S and du=2, the distance from "cool" to "boo." This again does not improve upon dbest=2. Each outgoing arc from "boo" is now considered; the arc from "boo" to "boon" has weight 1, and since |2−1|=1<dbest=2, "boon" is added to S. Similarly, since |2−2|=0<dbest, "cook" is also added to S. Finally each of the two last elements in S are considered in arbitrary order: suppose the node containing "cook" is popped first, improving dbest to distance 1, then the node containing "boon" is popped last, which has distance 2 from "cool" and therefore does not improve the best result. Finally, "cook" is returned as the answer wbest with dbest=1.

… excerpt ends here. Continue reading the full article.

Illustrations

BK-tree: The structure of the BK-tree is shown in the diagram: every node in a subtree is equidistant from the root
The structure of the BK-tree is shown in the diagram: every node in a subtree is equidistant from the root
BK-tree: An example of BK-tree
An example of BK-tree

Worked examples

Example 1 — a first encounter with BK-tree

Start with the simplest possible case. Write down what BK-tree 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 BK-tree 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 BK-tree 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 BK-tree

In research
BK-tree 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 BK-tree 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
BK-tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics Trees (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for BK-tree 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 “BK-tree” →

How to study BK-tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what BK-tree 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 BK-tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is BK-tree in simple terms?

A BK-tree (short for Burkhard-Keller tree) is a metric tree suggested by Walter Austin Burkhard and Robert M. Keller[1] specifically adapted to discrete metric spaces.

Why does BK-tree 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 BK-tree?

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 BK-tree.

Tags

  • Trees (data structures)

Keep exploring